Gathering detailed insights and metrics for s3-upload-stream
Gathering detailed insights and metrics for s3-upload-stream
Gathering detailed insights and metrics for s3-upload-stream
Gathering detailed insights and metrics for s3-upload-stream
A Node.js module for streaming data to Amazon S3 via the multipart upload API
npm install s3-upload-stream
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
347 Stars
82 Commits
46 Forks
5 Watching
14 Branches
7 Contributors
Updated on 26 Jun 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-9.3%
4,101
Compared to previous day
Last week
25.4%
28,291
Compared to previous week
Last month
11.7%
109,113
Compared to previous month
Last year
-20.9%
1,416,988
Compared to previous year
A pipeable write stream which uploads to Amazon S3 using the multipart file upload API.
NOTE: This module is deprecated after the 2.1.0 release of the AWS SDK on Dec 9, 2014, which added S3.upload()
. I highly recommend switching away from this module and using the official method supported by AWS.
Removing global state, and adding pause and resume functionality.
1var AWS = require('aws-sdk'), 2 zlib = require('zlib'), 3 fs = require('fs'); 4 s3Stream = require('s3-upload-stream')(new AWS.S3()), 5 6// Set the client to be used for the upload. 7AWS.config.loadFromPath('./config.json'); 8 9// Create the streams 10var read = fs.createReadStream('/path/to/a/file'); 11var compress = zlib.createGzip(); 12var upload = s3Stream.upload({ 13 "Bucket": "bucket-name", 14 "Key": "key-name" 15}); 16 17// Optional configuration 18upload.maxPartSize(20971520); // 20 MB 19upload.concurrentParts(5); 20 21// Handle errors. 22upload.on('error', function (error) { 23 console.log(error); 24}); 25 26/* Handle progress. Example details object: 27 { ETag: '"f9ef956c83756a80ad62f54ae5e7d34b"', 28 PartNumber: 5, 29 receivedSize: 29671068, 30 uploadedSize: 29671068 } 31*/ 32upload.on('part', function (details) { 33 console.log(details); 34}); 35 36/* Handle upload completion. Example details object: 37 { Location: 'https://bucketName.s3.amazonaws.com/filename.ext', 38 Bucket: 'bucketName', 39 Key: 'filename.ext', 40 ETag: '"bf2acbedf84207d696c8da7dbb205b9f-5"' } 41*/ 42upload.on('uploaded', function (details) { 43 console.log(details); 44}); 45 46// Pipe the incoming filestream through compression, and up to S3. 47read.pipe(compress).pipe(upload);
Before uploading you must configure the S3 client for s3-upload-stream to use. Please note that this module has only been tested with AWS SDK 2.0 and greater.
This module does not include the AWS SDK itself. Rather you must require the AWS SDK in your own application code, instantiate an S3 client and then supply it to s3-upload-stream.
The main advantage of this is that rather than being stuck with a set version of the AWS SDK that ships with s3-upload-stream you can ensure that s3-upload-stream is using whichever verison of the SDK you want.
When setting up the S3 client the recommended approach for credential management is to set your AWS API keys using environment variables or IAM roles.
If you are following this approach then you can configure the S3 client very simply:
1var AWS = require('aws-sdk'), 2 s3Stream = require('../lib/s3-upload-stream.js')(new AWS.S3());
However, some environments may require you to keep your credentials in a file, or hardcoded. In that case you can use the following form:
1var AWS = require('aws-sdk'); 2 3// Make sure AWS credentials are loaded using one of the following techniques 4AWS.config.loadFromPath('./config.json'); 5AWS.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'}); 6 7// Create a stream client. 8var s3Stream = require('../lib/s3-upload-stream.js')(new AWS.S3());
Create an upload stream that will upload to the specified destination. The upload stream is returned immeadiately.
The destination details is an object in which you can specify many different destination properties enumerated in the AWS S3 documentation.
Example:
1var AWS = require('aws-sdk'), 2 s3Stream = require('../lib/s3-upload-stream.js')(new AWS.S3()); 3 4var read = fs.createReadStream('/path/to/a/file'); 5var upload = s3Stream.upload({ 6 Bucket: "bucket-name", 7 Key: "key-name", 8 ACL: "public-read", 9 StorageClass: "REDUCED_REDUNDANCY", 10 ContentType: "binary/octet-stream" 11}); 12 13read.pipe(upload);
Resume an incomplete multipart upload from a previous session by providing a session
object with an upload ID, and ETag and numbers for each part. destination
details is as above.
Example:
1var AWS = require('aws-sdk'), 2 s3Stream = require('../lib/s3-upload-stream.js')(new AWS.S3()); 3 4var read = fs.createReadStream('/path/to/a/file'); 5var upload = s3Stream.upload( 6 { 7 Bucket: "bucket-name", 8 Key: "key-name", 9 ACL: "public-read", 10 StorageClass: "REDUCED_REDUNDANCY", 11 ContentType: "binary/octet-stream" 12 }, 13 { 14 UploadId: "f1j2b47238f12984f71b2o8347f12", 15 Parts: [ 16 { 17 ETag: "3k2j3h45t9v8aydgajsda", 18 PartNumber: 1 19 }, 20 { 21 Etag: "kjgsdfg876sd8fgk3j44t", 22 PartNumber: 2 23 } 24 ] 25 } 26); 27 28read.pipe(upload);
The following methods can be called on the stream returned by from client.upload()
Pause an active multipart upload stream.
Calling pause()
will immediately:
pausing
event with the number of parts that are still mid-upload.When mid-upload parts are finished, a paused
event will fire, including an object with UploadId
and Parts
data that can be used to resume an upload in a later session.
Resume a paused multipart upload stream.
Calling resume()
will immediately:
resume
event back to any listeners.It is safe to call resume()
at any time after pause()
. If the stream is between pausing
and paused
, then resume()
will resume data flow and the paused
event will not be fired.
Used to adjust the maximum amount of stream data that will be buffered in memory prior to flushing. The lowest possible value, and default value, is 5 MB. It is not possible to set this value any lower than 5 MB due to Amazon S3 restrictions, but there is no hard upper limit. The higher the value you choose the more stream data will be buffered in memory before flushing to S3.
The main reason for setting this to a higher value instead of using the default is if you have a stream with more than 50 GB of data, and therefore need larger part sizes in order to flush the entire stream while also staying within Amazon's upper limit of 10,000 parts for the multipart upload API.
1var AWS = require('aws-sdk'), 2 s3Stream = require('../lib/s3-upload-stream.js')(new AWS.S3()); 3 4var read = fs.createReadStream('/path/to/a/file'); 5var upload = s3Stream.upload({ 6 "Bucket": "bucket-name", 7 "Key": "key-name" 8}); 9 10upload.maxPartSize(20971520); // 20 MB 11 12read.pipe(upload);
Used to adjust the number of parts that are concurrently uploaded to S3. By default this is just one at a time, to keep memory usage low and allow the upstream to deal with backpressure. However, in some cases you may wish to drain the stream that you are piping in quickly, and then issue concurrent upload requests to upload multiple parts.
Keep in mind that total memory usage will be at least maxPartSize
* concurrentParts
as each concurrent part will be maxPartSize
large, so it is not recommended that you set both maxPartSize
and concurrentParts
to high values, or your process will be buffering large amounts of data in its memory.
1var AWS = require('aws-sdk'), 2 s3Stream = require('../lib/s3-upload-stream.js')(new AWS.S3()); 3 4var read = fs.createReadStream('/path/to/a/file'); 5var upload = s3Stream.upload({ 6 "Bucket": "bucket-name", 7 "Key": "key-name" 8}); 9 10upload.concurrentParts(5); 11 12read.pipe(upload);
The following configuration tuning can help prevent errors when using less reliable internet connections (such as 3G data if you are using Node.js on the Tessel) by causing the AWS SDK to detect upload timeouts and retry.
1var AWS = require('aws-sdk'); 2AWS.config.httpOptions = {timeout: 5000};
npm install s3-upload-stream
npm test
(The MIT License)
Copyright (c) 2014-2015 Nathan Peck https://github.com/nathanpeck
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 4/21 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More