Skip to content

Conversation

lsegal
Copy link
Contributor

@lsegal lsegal commented Dec 4, 2014

This pull requests adds support for AWS.S3.upload(), which allows uploading of large or arbitrarily sized buffer/stream objects in parallel parts (when possible). This PR also adds the AWS.S3.ManagedUpload abstraction, which is the underlying object that manages the uploads.
This abstraction works by performing a multipart upload when there is more than 5MB of buffered data to upload.

Example usage:

var fs = require('fs');
var zlib = require('zlib');

var body = fs.createReadStream('bigfile').pipe(zlib.createGzip());
var s3obj = new AWS.S3({params: {Bucket: 'myBucket', Key: 'myKey'}});
s3obj.upload({Body: body}).
  on('httpUploadProgress', function(evt) { console.log(evt); }).
  send(function(err, data) { console.log(err, data) });

Or via the ManagedUpload class directly:

var fs = require('fs');
var zlib = require('zlib');

var params = {
  Bucket: 'myBucket',
  Key: 'myKey',
  Body: fs.createReadStream('bigfile').pipe(zlib.createGzip())
}

var upload = new AWS.S3.ManagedUpload({params: params});
upload.on('httpUploadProgress', function(evt) { console.log(evt); });
upload.send(function(err, data) { console.log(err, data) });

It is possible to configure concurrency with the queueSize configuration option:

// uploads data 2 parts (of 10mb chunks) at a time
var options = {queueSize: 2, partSize: 1024 * 1024 * 10};
var upload = s3.upload(params, options, function(err, data) {
  console.log(err ? "FAILED!" : "DONE!");
});

By default this abstraction will cleanup a multipart upload if an error occurs on any part, though it is possible to set leavePartsOnError to true to avoid cleanup and handle this manually.

lsegal and others added 18 commits October 18, 2014 19:51
Usage:

```js
var fs = require('fs');
var zlib = require('zlib');

var body = fs.createReadStream('bigfile').pipe(zlib.createGzip());
var s3obj = new AWS.S3({params: {Bucket: 'myBucket', Key: 'myKey'}});
s3obj.upload().
  on('httpUploadProgress', function(evt) { console.log(evt); }).
  send({Body: body}, function(err, data) {
    console.log(err, data)
  });
```

Or via the ManagedUpload class:

```js
var fs = require('fs');
var zlib = require('zlib');

var params = {
  Bucket: 'myBucket',
  Key: 'myKey',
  Body: fs.createReadStream('bigfile').pipe(zlib.createGzip())
}

var upload = new AWS.S3.ManagedUpload();
upload.on('httpUploadProgress', function(evt) { console.log(evt); });
upload.send(params, function(err, data) { console.log(err, data) });
```

References #135
otherwise, setting `Location` on `data` will raise.
pass error to callback early in finishSinglePart
API has changed to:

    AWS.S3.upload(params, [options], [callback])

If no callback is supplied, the operation returns an object that
can call `.send([callback])`.

Example:

    s3.upload({Body: body}, {queueSize: 10}, function(err, data) {
      console.log(err, data);
    });

    // or

    s3.upload({Body: body}, {queueSize: 10}).send(callback);

The `options` parameter can be omitted.
@lsegal lsegal added the feature-request A feature should be added or improved. label Dec 4, 2014
@coveralls
Copy link

Coverage Status

Coverage increased (+0.23%) when pulling 24ce3a7 on s3-managed-upload into 89c20ed on master.

lsegal added a commit that referenced this pull request Dec 10, 2014
@lsegal lsegal merged commit 15a22eb into master Dec 10, 2014
lsegal added a commit that referenced this pull request Dec 10, 2014
@lock
Copy link

lock bot commented Sep 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 28, 2019
@trivikr trivikr deleted the s3-managed-upload branch January 5, 2021 02:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature-request A feature should be added or improved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants