Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

simple-do-spaces

0.7.0 • Public • Published

Simple Digital Ocean Spaces Client

Build Status dependencies Status devDependencies Status License: MIT

Usage

Credentials setup

You can set the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_KEY as default credentials for the S3 SDK which is also used by Digital Ocean Spaces API.

Create client for Digital Ocean Spaces API

import SpacesClient from 'simples-do-spaces';
 
const client = new SpacesClient(
  'sfo2.digitaloceanspaces.com', // Required, Digital Ocean Spaces Endpoint
  'bucketName', // Required. Bucket name
  'accessKeyId', // Optional. Access key, can be provided via env var AWS_ACCESS_KEY_ID
  'secretAccessKey' // Optional. Access key secret, can be env var AWS_SECRET_ACCESS_KEY
);
 

All methods returns a Promise which resolves to the values described below.

Upload file

client.uploadFile(uploadFilePath, destinationPath, permission);
  • uploadFilePath : File path in file system
  • destinationPath : Path to save in DO Spaces
  • permission : Permission of the file, default is private, can also be public-read.
  • options : Options object to be sent to S3 SDK
    • exponentialBackoff : Use exponential backoff if the upload failed

Return file URL in DO Spaces CDN

List files

client.listPathFiles(path, options = {});
  • path : Path in DO Spaces to list
  • options : Options object
    • sortByDate : Sort files by LastModified date, can be 'ASC' (default) or 'DESC'
    • pathOnly : If true it will not return the complete URL just the path in DO Spaces

Return array of objects with the 'url' and 'lastModified' properties

[ { url: 'file url', lastModified: Date }, ... ]

Delete one file

client.deleteFile(path);
  • path : Relative path to one file in DO spaces to delete it

Delete multiple files

client.deletePaths(paths);
  • paths : Array of relative paths in DO spaces to delete

Copy file within DO Spaces

client.copyFile(sourcePath, destinationPath);

Download file

client.downloadFile(filePathToRead, filePathToSave, createDirIfNotExists);
  • filePathToRead : Path in DO Spaces
  • filePathToSave : Path to save in file system
  • createDirIfNotExists : Boolean to create the folder if the it doesn't exists. Default is true

License

MIT © Bruno Orlandi

Install

npm i simple-do-spaces

DownloadsWeekly Downloads

200

Version

0.7.0

License

MIT

Unpacked Size

28.5 kB

Total Files

5

Last publish

Collaborators

  • avatar