Google Cloud Storage file write stream fails

Viewed 2654

Hi i am trying to write a file in google cloud storage using node.js.

When i try to write the file, i get the following error

{
  "errors": [
    {
      "domain": "global",
      "reason": "badRequest",
      "message": "Invalid Upload Request"
    }
  ],
  "code": 400,
  "message": "Invalid Upload Request"
}

Below is part of the code used to write the file

const storageClient = require( '@google-cloud/storage' );
var storage = storageClient({ projectId: config.gcsProjectId }).bucket( config.gcsBucket );
var gcsStream = storage.file( this.config.fileName ).createWriteStream();
var entities = {}//huge json object;
Object.values( entities ).forEach( (json) => {
    var str = JSON.stringify( json );
    gcsStream.write( str + '\n' );
});
gcsStream.on('error', (err) => {
    console.error(`${ this.archive }: Error storage file write.`);
    console.error(`${ this.archive }: ${JSON.stringify(err)}`);
});
gcsStream.end();

I am using node 8.3.0, npm 5.4.1, @google-cloud/storage 1.3.0

1 Answers

Alright, I seemed to have solved my issue; Same issue you're experiencing. I was getting this error because my filename contained "dashes." After removing it from the filename, it uploaded successfully w/o any errors. Good luck!

Related