Skip to content

Storage File.download error #494

Description

@Marc477

I think there is an error in this function (storage/file.js):

File.prototype.download = function(options, callback) {
 if (util.is(options, 'function')) {
 callback = options;
 options = {};
}

callback = once(callback);

var destination = options.destination;
delete options.destination;

var fileStream = this.createReadStream(options);

if (destination) {
 fileStream
  .on('error', callback)
  .pipe(fs.createWriteStream(destination))
  .on('error', callback)
  .on('finish', callback);
} else {
var fileContents = new Buffer('');

fileStream
  .on('error', callback)
  .on('data', function(chunk) {
    fileContents = Buffer.concat([fileContents, chunk]);
  })
  .on('complete', function() {
    callback(null, fileContents);
  });
}
};

I dont use the destination option, and the function works, but if I have multiple requests to the same file. Then somtimes the download is pending and never returns anything...

I don't know if it is the once(callback) because it is the same callback for multiple requests but this is strange, I replaced the function with my own code and now it is working:

var iStream = file.gFile.createReadStream();
var fileData = new Buffer('');

iStream.on('error', function(err){
   Log.error(err);
   loadCB(null);
});

iStream.on('data', function(data){
   fileData = Buffer.concat([fileData, data]);
});

iStream.on('complete', function() {
   loadCB(fileData);
});

Activity

  1. added
    api: storageIssues related to the Cloud Storage API.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Apr 13, 2015
  2. stephenplusplus commented on Apr 13, 2015

    @stephenplusplus
    Contributor

    Thanks for looking into this! Can you demonstrate how you are making multiple requests?

  3. Marc477 commented on Apr 13, 2015

    @Marc477
    Author

    I'm hosting videos on google storage, I use a xml file to retreive the info of the video but I have to edit it server side before sending it to the client (so I use .download to get the xml file from storage to compute engine). If I start 7-8 pages at the same time in my browser, then they all try to get the xml file but some of them will never get a response (pending....) and no errors are thrown server side.

    With the second code below I don't get this error

  4. callmehiphop commented on Jul 28, 2015

    @callmehiphop
    Contributor

    @Marc477 Are you still experiencing this issue? If so, could you provide code snippets on how you were using File#download (options, etc.)?

    once doesn't augment the actual function, so you should be able to re-use the same callback as many times as you like.

  5. stephenplusplus commented on Aug 24, 2015

    @stephenplusplus
    Contributor

    We've made multiple changes to some core aspects of our library since this issue was opened. Without more details, it's hard for us to debug. I hope it's been resolved since you opened this issue @Marc477, but if not, please re-open with anything else you can share that will help us catch the bug.

  6. added a commit that references this issue on Sep 27, 2022
  7. 26 remaining items

  8. added a commit that references this issue on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🚨This issue needs some love.api: storageIssues related to the Cloud Storage API.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions