Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws-sdk Multipart Upload to s3 with node.js

I am trying to upload files to a s3 bucket using the node js aws-sdk V3.

I know I am supposed to be using the commmands: CreateMultipartUploadCommand,UploadPartCommandand so forth. But I can't find any working example of a full multipart upload.

Can anyone share any code samples?

Thanks in advance

like image 292
Adi Fuchs Avatar asked Feb 16 '26 00:02

Adi Fuchs


1 Answers

I put together a bit of code for this: https://gist.github.com/kbanman/0aa36ffe415cdc6c44293bc3ddb6448e

The idea is to upload a part to S3 whenever we receive a chunk of data in the stream, and then finalize the upload when the stream is finished.

Complicating things is S3's minimum part size of 5MB on all but the last part in the series. This means that we need to buffer data until we can form those 5MB chunks. I accomplished this using a transformer that adds back-pressure on the content stream between each chunk upload.

Parallelization is also made difficult by the fact that S3 insists on receiving the parts in order (despite asking for the parts to be numbered).

like image 120
kbanman Avatar answered Feb 18 '26 17:02

kbanman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!