Skip to content

Can't upload file to s3 when file size is 0 #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
clues opened this issue Mar 28, 2015 · 4 comments · Fixed by #562 or #601
Closed

Can't upload file to s3 when file size is 0 #549

clues opened this issue Mar 28, 2015 · 4 comments · Fixed by #562 or #601

Comments

@clues
Copy link

clues commented Mar 28, 2015

When file size is 0,i can't upload file to s3,Use wireshark tools i found sdk not send http request to s3.
my code:
s3obj.upload({Body: body}).send(cb);

i modify two code in l lib/s3/managed_upload.js file and it't work:

/**

  • @api private
    */
    fillStream: function fillStream() {
    var self = this;
    if (self.activeParts >= self.queueSize) return;

    var buf = self.body.read(self.partSize - self.partBuffer.length) ||
    self.body.read();
    if (buf) {
    self.partBuffer = AWS.util.Buffer.concat([self.partBuffer, buf]);
    self.totalChunkedBytes += buf.length;
    }

    if (self.partBuffer.length >= self.partSize) {
    self.nextChunk(self.partBuffer.slice(0, self.partSize));
    self.partBuffer = self.partBuffer.slice(self.partSize);
    } else if (self.isDoneChunking) {
    self.totalBytes = self.totalChunkedBytes;
    if (self.partBuffer.length >= 0) { // change self.partBuffer.length > 0 to self.partBuffer.length >= 0
    self.numParts++;
    self.nextChunk(self.partBuffer);
    }
    self.partBuffer = new AWS.util.Buffer(0);
    }

    self.body.read(0);
    }

    /**

  • @api private
    */
    adjustTotalBytes: function adjustTotalBytes() {
    var self = this;
    try { // try to get totalBytes
    self.totalBytes = byteLength(self.body);
    } catch (e) { }

    // try to adjust partSize if we know payload length
    if (self.totalBytes) {
    var newPartSize = Math.ceil(self.totalBytes / self.maxTotalParts);
    if (newPartSize > self.partSize) self.partSize = newPartSize;
    }else if(self.totalBytes ==0){ //When self.totalBytes is 0, it's not boolean false; so care of here
    self.totalBytes =0;
    }
    else {
    self.totalBytes = undefined;
    }
    }

===========

Please update to github source files

@lsegal
Copy link
Contributor

lsegal commented Mar 28, 2015

It's hard to know what's changed here. Would you mind packaging this up as a pull request? That way you can also get credit for your work!

@clues
Copy link
Author

clues commented Mar 28, 2015

@lsegal :OK

@lsegal lsegal added the Bug label Apr 2, 2015
@clues
Copy link
Author

clues commented Apr 2, 2015

Oh no, my code can upload empty file, but will lead to new problem: file size more than (4~5)mb seem will dead chunk and send large http request to s3.So i expect new solution.

@lock
Copy link

lock bot commented Sep 30, 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 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants