aws-s3-manager
v2.0.0
Published
A wrapper for AWS S3 to upload files
Downloads
5
Maintainers
Readme
A wrapper for AWS S3
Description
S3Client - A Javascript Library for AWS S3 File Upload If using it with browser setup cors
Installing
npm install aws-s3-manager
Getting started
Import
// es5 example
const { AwsS3Manager } = require('aws-s3-manager');
// es6 example
import { AwsS3Manager } from 'aws-s3-manager' ;
Initialize Client
- Initiate client with configuration (e.g. credentials: (cognito credential), region).
const client = await new AwsS3Manager({
REGION: <REGION> // us-west-1,
TYPE: 1,
IDENTITY_POOL_ID: <IDENTITY_POOL_ID> // '44c50347-c1e0-400a-b221-5b3127b738e8'
})
or
const client = await new AwsS3Manager({
REGION: <REGION> // us-west-1,
TYPE: 2,
ACCESS_KEY_ID: <ACCESS_KEY_ID>,
SECRET_ACCESS_KEY: <SECRET_ACCESS_KEY>
})
List Bucket
const { error, message, data } = await client.listBucket();
if (error) {
console.log('error -->', message)
return
}
Create Bucket
const { error, message, data } = await client.createBucket({ Bucket: <BUCKET_NAME> });
if (error) {
console.log('error -->', message)
return
}
Delete Bucket
const { error, message, data } = await client.deleteBucket({ Bucket: <BUCKET_NAME> });
if (error) {
console.log('error -->', message)
return
}
List Objects
const { error, message, data } = await client.getObjectList({ Bucket: <BUCKET_NAME> });
if (error) {
console.log('error -->', message)
return
}
Upload Object
const uploadParams = {
ACL: "authenticated-read" | "aws-exec-read" | "bucket-owner-full-control" | "bucket-owner-read" | "private" | "public-read" | "public-read-write",
Body: <FILE_BODY>,
Bucket: <BUCKET_NAME>,
Key: <FILE_NAME>
}
const { error, message, data } = await client.uploadObject(uploadParams);
if (error) {
console.log('error -->', message)
return
}
Get Object
const getParams = {
Bucket: <BUCKET_NAME>,
Key: <FILE_NAME>
}
const { error, message, data } = await client.getObject(getParams);
if (error) {
console.log('error -->', message)
return
}
Generate Get Object Signed URL
const getParams = {
Bucket: <BUCKET_NAME>,
Key: <FILE_NAME>
}
const { error, message, data } = await client.getPresignedUrl(getParams);
if (error) {
console.log('error -->', message)
return
}
Generate Upload Object Signed URL
const uploadParams = {
ACL: "authenticated-read" | "aws-exec-read" | "bucket-owner-full-control" | "bucket-owner-read" | "private" | "public-read" | "public-read-write",
Bucket: <BUCKET_NAME>,
Key: <FILE_NAME>
}
const { error, message, data } = await client.putPresignedUrl(uploadParams);
if (error) {
console.log('error -->', message)
return
}