@letgowebteam/s3
v1.3.0
Published
S3 utilities wrapper
Downloads
8
Readme
@letgowebtools/s3
s3 is a utility package that wraps the AWS sdk for some methods. All the functions exported here assume that you have permission to access the corresponding s3 resources.
Installing
npm install @letgowebteam/s3
Usage
downloadS3Object
Useful if you want to download a single file from an S3 bucket to disk by returning a promise. To call this function we need to pass the following required data:
| Parameter | Type | | ---------- | ------------------- | | options | S3.GetObjectRequest | | pathToSave | string |
Example:
const s3 = require('@letgowebtools/s3');
(async() => {
const options: S3.GetObjectRequest = {
Bucket: 'my_bucket',
Key: 'my_sub_folder/my_file.txt',
};
const pathToSave = '/tmp/';
await s3.downloadS3Object(options, pathToSave);
})();
uploadDirToS3
Uploads the specified folder or its contents only to s3 recursively to the specified S3 bucket. To call this function we need to pass the following required data:
| Parameter | Type | Purpose | | --------------------- | ------ | --------------------------------------------------- | | dirPath | string | Origin path to upload | | removePrefixBucketKey | string | Prefix folder to remove | | bucketName | string | Bucket name where files are goint to be uploaded to |
If we only want to upload its contents we will have to pass in the 'removePrefixBucketKey' with the part of the path to remove, otherwise an empty string.
Output types:
| Output | Type | | ------ | ------------------ | | Output | S3.PutObjectOutput |
Example:
const s3 = require('@letgowebtools/s3');
(async() => {
const dirPath = '/tmp/';
const removePrefixBucketKey = '/tmp/';
const bucketName = 'my_bucket';
const output = await s3.uploadDirToS3(dirPath, removePrefixBucketKey, bucketName);
})();