A package to handle the S3 requests
npm install @janiscommerce/s3This is a wrapper for the AWS SDK for the management S3 request, that makes easier the use of it.
For more information read the AWS S3 SDK.
Since
v2.0.0you need Node 18
The possible methods are:
getObjectgetObjectRawputObjectheadObjectcopyObjectdeleteObjectdeleteObjectslistObjectslistBucketscreateBucketdeleteBucketgetSignedUrlcreatePresignedPost
Since the package updates to use SDK v3 and Node-18 compatibility, when use getObject, it returns the Body as an Readable type. This change is not compatible with previous uses.
So getObject method convert the Body into a Buffer type object, to keep the compatibility with previous uses.
If you wanted the original behavior, you can use
getObjectRaw.
const S3 = require('@janiscommerce/s3');
try {
const s3Response = await S3.putObject({
Body: 'File content',
Bucket: 'bucket-ame',
Key: `path/to/file.txt`
});
console.log(s3Response);
} catch(err) {
handleError(err);
}For manage stream the package provide
The class to get, parse and process S3 streams.
const { GetObjectStream } = require('@janiscommerce/s3');
class MyGetObjectStream extends GetObjectStream {
// Parse the incoming data before process rows
get parsers() {
return [
/*
* Your parsers here as array, where:
* [function, ...params]
*/
]
}
// Manage the buffer rows size
get bufferSize() {
return 10;
}
// Process the buffered rows and return and array to continue.
async processBuffer(buffer) {
// ... Your logic here ...
}
}
const myGetObjectStream = new MyGetObjectStream();
const myProcessedStream = myGetObjectStream.call({
Bucket: 'bucket-ame',
Key: `path/to/file.txt`
});Method to manage streams upload
const { uploadStream } = require('@janiscommerce/s3');
try {
const response = await uploadStream(someStream, {
Bucket: 'bucket-ame',
Key: `path/to/file.txt`
});
} catch(e) {
console.log(e)
}