1.0.0 • Published 2 years ago

wasabi-s3 v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

This repo is an updated version of https://bitbucket.org/javidgon/solid-bucket/src/master/ for wasabi deployments only.

2.7 Wasabi Object Storage

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

3. Universal API

3.1 Create a Bucket

3.1.1 Definition

provider.createBucket(bucketName); // returns a Promise

3.1.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
provider
  .createBucket(bucketName)
  .then((resp) => {
    if (resp.status === 201) {
      console.log(resp.message);
      // Output: Bucket "example" was created successfully
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });

3.2 Delete a Bucket

3.2.1 Definition

provider.deleteBucket(bucketName); //  returns a Promise

3.2.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
provider
  .deleteBucket(bucketName)
  .then((resp) => {
    if (resp.status === 200) {
      console.log(resp.message);
      // Output: Bucket "example" was deleted successfully
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });

3.3 Upload File

3.3.1 Definition

provider.uploadFile(bucketName, filePath); //  returns a Promise

3.3.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
let filePath = '/tmp/file.bin';
provider
  .uploadFile(bucketName, filePath)
  .then((resp) => {
    if (resp.status === 200) {
      console.log(resp.message);
      // Output: Bucket "example" was deleted successfully
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });

3.4 Download File

3.4.1 Definition

provider.deleteBucket(bucketName, remoteFilename downloadedFilePath) //  returns a Promise

3.4.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
let remoteFilename = 'file.bin';
let downloadedFilePath = '/tmp';
provider
  .downloadFile(bucketName, remoteFilename, downloadedFilePath)
  .then((resp) => {
    if (resp.status === 200) {
      console.log(resp.message);
      // Output: Bucket "example" was deleted successfully
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });

3.5 Create File from Text in Bucket

3.5.1 Definition

provider.createFileFromText(bucketName, remoteFilename, text); // returns a Promise

3.5.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
let remoteFilename = 'my_remote_object.txt';
let text = 'This is a text that I would like to upload';
provider
  .createFileFromText(bucketName, remoteFilename, text)
  .then((resp) => {
    if (resp.status === 200) {
      console.log(resp.message);
      // Output: Object "example.txt" was saved successfully in bucket "example"
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });

3.6 Delete file from Bucket

3.6.1 Definition

provider.deleteFile(bucketName, remoteFilename); // returns a Promise

3.6.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
let remoteFilename = 'my_remote_object.txt';

provider
  .deleteFile(bucketName, remoteFilename)
  .then((resp) => {
    if (resp.status === 200) {
      console.log(resp.message);
      // Output: Object "example.txt" was deleted successfully from bucket "example"
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });

3.7 Read File from Bucket

3.7.1 Definition

provider.readFile(bucketName, remoteFilename); // returns a Promise

3.7.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
let remoteFilename = 'my_remote_object.txt';
provider
  .readFile(bucketName, remoteFilename)
  .then((resp) => {
    if (resp.status === 200) {
      console.log(resp.message);
      // Output: Object "example.txt" was fetched successfully from bucket "example"
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });

3.8 Get list of objects from Bucket

3.8.1 Definition

provider.getListOfFiles(bucketName); // returns a Promise

3.8.2 Full Example

const WasabiS3 = require('wasabi-s3');

let provider = new WasabiS3('wasabi', {
  accessKeyId: 'accessKeyId',
  secretAccessKey: 'secretAccessKey',
});

let bucketName = 'example';
provider
  .getListOfFiles(bucketName)
  .then((resp) => {
    if (resp.status === 200) {
      console.log(resp.message);
      // Output: The list of objects was fetched successfully from bucket "example"
    }
  })
  .catch((resp) => {
    if (resp.status === 400) {
      console.log(resp.message);
      // Output: Some error coming from the provider...
    }
  });