kow-do-spaces

A simple wrapper that lets you upload and delete files in DigitalOcean's spaces object storage in case you do not want to add aws-sdk to your project's dependencies directly since it can be really annoying to have tons of types with names that you use in your project.

Usage no npm install needed!

<script type="module">
  import kowDoSpaces from 'https://cdn.skypack.dev/kow-do-spaces';
</script>

README

Kow Do-Spaces

A simple wrapper that lets you upload and delete files in DigitalOcean's spaces object storage in case you do not want to add aws-sdk to your project's dependencies directly since it can be really annoying to have tons of types with names that you use in your project.

Disclaimer

This is not a production ready package (although it is pretty straight-forward).

Installation

yarn add kow-do-spaces

or

npm install kow-do-spaces

Features

  • uploadFile: Uploads a file with the specified options, returning its key and download url (location).
  • deleteFile: Deletes a file by providing a bucket and a key.

Usage

Instantiate the class

const spaces = new Spaces({
  endpoint: 'nyc3.digitalocean...',
  key: 'access key obtained from digital ocean',
  secret: 'secret key obtained from digital ocean',
});

Upload a file

const response = await spaces.uploadFile({
  file: file,
  bucket: 'my-bucket',
  acl: 'public-read',
  key: 'my-custom-key', // use forward slashes for folders
  contentType: file.mimetype,
);

console.log(response.key); // my-custom-key
console.log(response.location); // https://my-bucket.nyc3.digitaloceanspaces.com/my-custom-key

Delete a file

await spaces.deleteFile({
  bucket: 'my-bucket',
  key: 'my-custom-key',
);

Contributing

Feel free to contribute in any way you'd like. You can email me at kaionesyan@gmail.com if you have any questions.