aws-s3-upload-ash
Open Source Module to Upload your Media and files into AWS S3 Bucket directly from Front-end.
AWSS3UploadAsh - A Javascript Library for AWS S3 File Upload
Donate
http://bit.ly/doeismaelnascimento
How to use(youtube)
- How to use with React =
- How to use with Angular =
How get
Using NPM
npm install aws-s3-upload-ash
Using Yarn
yarn add aws-s3-upload-ash
Examples Uploading a file
Uploading to S3 with bucket public
import AWSS3UploadAsh from 'aws-s3-upload-ash';
const config = {
bucketName: 'bucketName',
dirName: 'media',
region: 'us-east-1',
accessKeyId: process.env.accessKeyId,
secretAccessKey: process.env.secretAccessKey,
s3Url: 'https://bucketName.s3.amazonaws.com/'
}
const S3CustomClient = new AWSS3UploadAsh(config);
const newFileNameWithExtesion = 'myPdf.pdf';
S3CustomClient
.uploadFile(file, "application/pdf", undefined, newFileNameWithExtesion, undefined)
.then(data => console.log(data))
.catch(err => console.error(err))
});
Uploading to S3 with presignedURL
import AWSS3UploadAsh from 'aws-s3-upload-ash';
const S3CustomClient = new AWSS3UploadAsh();
S3CustomClient
.uploadFile(file, "application/png", "presignedlURL", undefined, undefined)
.then(data => console.log(data))
.catch(err => console.error(err))
});
Uploading to S3 with bucket public and without directory
import AWSS3UploadAsh from 'aws-s3-upload-ash';
const config = {
bucketName: 'bucketName',
region: 'us-east-1',
accessKeyId: process.env.accessKeyId,
secretAccessKey: process.env.secretAccessKey,
s3Url: 'https://bucketName.s3.amazonaws.com/'
}
const S3CustomClient = new AWSS3UploadAsh(config);
const newFileNameWithExtesion = 'myVideo.mp4';
S3CustomClient
.uploadFile(file, "video/mp4", undefined, newFileNameWithExtesion, undefined)
.then(data => console.log(data))
.catch(err => console.error(err))
});
Deleting an existing file into directory in your bucket public
In this case the file that we want to delete is in the folder 'photos'
import AWSS3UploadAsh from 'aws-s3-upload-ash';
const config = {
bucketName: 'bucketName',
dirName: 'media',
region: 'us-east-1',
accessKeyId: process.env.accessKeyId,
secretAccessKey: process.env.secretAccessKey,
s3Url: 'https://bucketName.s3.amazonaws.com/'
}
const S3CustomClient = new AWSS3UploadAsh(config);
const newFileNameWithExtesion = 'fileName.extesion';
S3CustomClient
.deleteFile(newFileNameWithExtesion)
.then(response => console.log(response))
.catch(err => console.error(err))
});
Deleting an existing file without directory in your bucket public
import AWSS3UploadAsh from 'aws-s3-upload-ash';
const config = {
bucketName: 'bucketName',
region: 'us-east-1',
accessKeyId: process.env.accessKeyId,
secretAccessKey: process.env.secretAccessKey,
s3Url: 'https://bucketName.s3.amazonaws.com/'
}
const S3CustomClient = new AWSS3UploadAsh(config);
const newFileNameWithExtesion = 'fileName.extesion';
S3CustomClient
.deleteFile(newFileNameWithExtesion)
.then(response => console.log(response))
.catch(err => console.error(err))
});
Important
- If you bucket is public use only this parameters: file, contentType, newFileNameWithExtesion see the example above
- If you bucket is private(with Objects can be public) use presignedURL parameter (recommended)
AWS S3 Links
License
MIT