Skip to content

Latest commit

 

History

History
98 lines (72 loc) · 2.43 KB

Examples.md

File metadata and controls

98 lines (72 loc) · 2.43 KB

Examples

Connecting to Digital Ocean and selecting a space

use SpacesAPI\Spaces;

$spaces = new Spaces('api-key', 'api-secret');
$space = $spaces->space('space-name');

API docs for \SpacesAPI\Spaces

Creating a new space

$spaces = new Spaces('api-key', 'api-secret');
$space = $spaces->create('new-space-name');

API docs for creating a space

Listing files

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$files = $space->listFiles();

foreach ($files['files'] as $file) {
    echo "{$file->filename}\n";
}

API docs for listing files

Uploading a file

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$file = $space->uploadFile('./localfile.txt', 'remote-filename.txt');

API docs for uploading files

Uploading text to a file

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$file = $space->uploadText('Lorem ipsum', 'remote-filename.txt');

API docs for uploading text

Downloading a file

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->download('./localfile.txt');

API docs for downloading a file

Get the contents of a file

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
echo $space->file('filename.txt')->getContents();

API docs for getting the contents of a file

Deleting a file

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->delete();

API docs for deleting a file

Get a public URL

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->getURL();

API docs for getting the public URL

Get a signed URL

a time limited link to provide access to a private file

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->getSignedURL("1 day");

API docs for getting a signed URL

Make a file publicly accessible

$space = new Spaces('api-key', 'api-secret')->space('my-space-name');
$space->file('filename.txt')->makePublic();

API docs for setting file privacy