do-spaces
Unofficial package for simple managing file operations hosted on "Digital Ocean Spaces" written in Typescript
![do-spaces unnoficial package readme banner](https://user-images.githubusercontent.com/8983870/239910462-a037cf98-6bce-4c8b-9399-a4382f6a41c2.png)
Motivation
I've created this package to ease working with spaces. Be more expressive then aws-sdk
. And to solve "quirks" aws-sdk
have (like uploading with mime-types, delete whole folder...)
Install
npm i do-spaces
Usage
const Spaces = require('do-spaces').default;
import Spaces from 'do-spaces';
const spaces = new Spaces({
endpoint: `<endpoint>`,
accessKey: `<access_key>`,
secret: `<secret>`,
bucket: `<name_of_the_bucket>`,
});
Methods
- every method takes optional
awsParams
to enhance/replace it's default configuration for underlying method. Configuration docs can be found here path
- string, path folder like (ending with /
)pathname
-- string, full path to file (e.g /test/image.png
)- all methods returns
Promise
const spaces = new Spaces({
endpoint: `<endpoint>`,
accessKey: `<access_key>`,
secret: `<secret>`,
bucket: `<name_of_the_bucket>`,
});
await spaces.createFolder({
path: `/some/test/path/`,
awsParams
});
await spaces.deleteFolder({
path: `/some/test/path/`,
awsListParams,
awsDeleteParams,
});
await spaces.uploadFile({
pathname: `/some/test/path/myfile.txt`,
privacy: "public-read",
file,
awsParams
});
await spaces.downloadFile({
pathname: "/some/test/path/myfile.txt",
awsParams
});
await spaces.listFiles({
maxFiles = 1000,
path: `/some/test/path/` ,
nextMarker,
awsParams,
});
await spaces.copyFile({
pathname: "/test/newFile.txt",
copiedPathname: "/test/copied.txt",
privacy: "public-read",
fromBucket,
awsParams,
});
await spaces.deleteFile({
pathname: "/test/remove_me.txt",
awsParams
});