An API wrapper for DigitalOcean's Spaces object storage designed for easy use.
Find a file
Devang Srivastava 2557aef44f Update 1: New functions, Error Handling, Unix Time & More
This is the first update!
-> Two new functions allow for easily making files public or private.
-> Files' public or private status can now be set while uploading.
-> Added error handling capabilities.
-> All time values are automatically converted to Unix time.
-> Result objects are automatically converted to arrays.
-> Fixed a bug with ACLs where a different client was being called.
-> Fixed a bug with file uploads where save as was not working.
2018-01-03 23:37:15 +05:30
aws Delete .DS_Store 2017-12-07 21:24:35 +05:30
LICENSE Initial commit 2017-12-07 20:59:09 +05:30
README.md Update README.md 2017-12-08 06:40:22 +05:30
spaces.php Update 1: New functions, Error Handling, Unix Time & More 2018-01-03 23:37:15 +05:30

Spaces-API

An API wrapper for DigitalOcean's Spaces object storage designed for easy use.

Connecting

require_once("spaces.php");

$key = "EXAMPLE_KEY";
$secret = "EXAMPLE_SECRET";

$space_name = "my-space";
$region = "nyc3";

$space = new SpacesConnect($key, $secret, $space_name, $region);

All available options:

SpacesConnect(REQUIRED KEY, REQUIRED SECRET, OPTIONAL SPACE's NAME, OPTIONAL REGION, OPTIONAL HOST);

 

Uploading/Downloading Files

$path_to_file = "folder/image.png";

$space->uploadFile($path_to_file);



$download_file = "image.png";
$save_as = "folder/downloaded-image.png";

$space->downloadFile($download_file, $save_as);

All available options:

uploadFile(REQUIRED PATH TO FILE, OPTIONAL NAME TO SAVE FILE AS);
downloadFile(REQUIRED FILE TO DOWNLOAD, REQUIRED LOCATION TO SAVE FILE);

 

$file = "image.png";
$valid_for = "1 day";

$link = $space->CreateTemporaryURL($file, $valid_for);

All available options:

   

Other File APIs

//List all files and folders
$files = $space->listObjects();


//Check if a file/folder by that name already exists. True/False.
$space->doesObjectExist($file_name);


//Pull information about a single object.
$file_info = $space->getObject($file_name);


//Delete a file/folder.
$space->deleteObject($file_name);


//Upload a complete directory instead of a single file.
$space->uploadDirectory($path_to_directory, $key_prefix);


//Pull Access Control List information.
$acl = $space-listObjectACL($file_name);


//Update Access Control List information.
$space->PutObjectACL($file_name, $acl_info_array);

         

Creating Spaces

$new_space = "my-new-space";

$space->createSpace($new_space);

All available options:

createSpace(REQUIRED SPACE NAME, OPTIONAL REGION FOR SPACE);

 

Switching Spaces

$new_space = "my-new-space";

$space->setSpace($new_space);

All available options:

setSpace(REQUIRED SPACE NAME, OPTIONAL REGION FOR SPACE, OPTIONAL HOST);

   

Other Spaces APIs

//List all Spaces available in account.
$spaces = $space->listSpaces();


//Delete a Space.
$space->destroyThisSpace();


//Download whole Space to a folder.
$space->downloadSpaceToDirectory($directory_to_download_to);


//Get the name of the current Space.
$space_name = $space->getSpaceName();


//Pull the CORS policy of the Space.
$cors = $space->listCORS();


//Update the CORS policy of the Space.
$space->putCORS($new_policy);


//Pull the Access Control List information of the Space.
$acl = $space->listSpaceACL();


//Update the Access Control List information of the Space.
$space->PutSpaceACL($new_acl);