DigitalOcean Spaces

Connect with DigitalOcean Spaces without any backend coding.

Overview

DigitalOcean Spaces provide S3-compatible object storage which lets you store and serve large amounts of data. SlashApi provide a simple API endpoint to connect with your DigitalOcean Spaces files using API without writing any backend code.

Getting Started

After you create an account and log in to the dashboard, choose DigitalOcean Spaces on the collections page. To make DigitalOcean Spaces API we need these values:

  • Access Key
  • Secret Access Key
  • Region
  • Bucket Name

Get your access key

Let's start with Spaces access keys to get your encryption key.

  1. On the left sidebar of your DigitalOcean dashboard select API OR Click Here
  2. Under the Tokens/Keys tab you will see Spaces access keys at the bottom of the page and click on Generate New Key button.
  3. Enter the name of your key and submit.
  4. After creating access key, you can put your Access key and Secret key on DigitalOcean Spaces API form.

Region and Bucket Name

To get the region and bucket name, you can see them on your spaces page. At the top of your spaces page you will see the name of your bucket name.

Spaces URL

From the example above, the spaces url are made up by two components. https://<bucket-name>.<region>.digitaloceanspaces.com

  • slashapi is your bucket name
  • sgp1 is your region

API Endpoints

List All Files

List all files in your DigitalOcean Spaces

GET
<team>/spaces/<identifier>/files

Parameters

Parameter Description
recursive Operating on a directory and its contents, including the contents of any subdirectories
directory Directory root

Example

var axios = require('axios');

var config = {
    method: 'get',
    url: 'http://v1.slashapi.com/slashapi/spaces/u2nyrJqa0f/files?directory=your-directory'
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });

List All Directories

List all directories in your DigitalOcean Spaces

GET
<team>/spaces/<identifier>/directories

Parameters

Parameter Description
recursive Operating on a directory and its contents, including the contents of any subdirectories
directory Directory root

Example

var axios = require('axios');

var config = {
    method: 'get',
    url: 'http://v1.slashapi.com/slashapi/spaces/u2nyrJqa0f/directories?directory=your-directory'
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });

Download File

Download File from your DigitalOcean Spaces

GET
<team>/spaces/<identifier>/download

Parameters

Parameter Description
path [required] Path to file

Example

var axios = require('axios');

var config = {
    method: 'get',
    url: 'http://v1.slashapi.com/slashapi/spaces/u2nyrJqa0f/download?path=path-to-file'
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });

Upload File

POST
<team>/spaces/<identifier>

Upload File to your DigitalOcean Spaces.

Request Body

Body Description
file [required] File to upload
directory Destination directory for your uploaded file

Example

var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('file', fs.createReadStream('/path/to/file'));
data.append('directory', 'target-directory');

var config = {
    method: 'post',
    url: 'http://v1.slashapi.com/slashapi/spaces/u2nyrJqa0f',
    headers: {
        ...data.getHeaders()
    },
    data : data
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });

Delete Files

Delete Files in your DigitalOcean Spaces

DELETE
<team>/spaces/<identifier>

Request Body

Body Description
files [required] Path to files. To delete multiple files, you can pass an array

Example

var axios = require('axios');
var data = JSON.stringify({
    "files": [
        "Directory/your-file.jpeg"
    ]
});

var config = {
    method: 'delete',
    url: 'http://v1.slashapi.com/slashapi/spaces/u2nyrJqa0f',
    headers: {
        'Content-Type': 'application/json'
    },
    data : data
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });

Delete Directory

Delete directory in your DigitalOcean Spaces

DELETE
<team>/spaces/<identifier>

Request Body

Body Description
directory [required] Target directory

Example

var axios = require('axios');
var data = JSON.stringify({
    "directory": "target-directory"
});

var config = {
    method: 'delete',
    url: 'http://v1.slashapi.com/slashapi/spaces/u2nyrJqa0f',
    headers: {
        'Content-Type': 'application/json'
    },
    data : data
};

axios(config)
    .then(function (response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
        console.log(error);
    });