简体   繁体   中英

Upload a csv file to GCP storage , 413 http code error

I uploaded a file about 1 GB, but a 413 time out error occurred. How can I solve it?

My code:

const storage = new Storage({
  keyFilename: 'some.json'
})
const bucket = storage.bucket("some");
const blob = bucket.file('upload/' + files[f].originalname)
const blobStream = blob.createWriteStream().on('finish', function() {
  console.log('[upload] finished')
});
blobStream.end(files[f].buffer)

This is a typically problem with a large file, you need to use the resumable upload feature of google api.

Or you can use the streaming transfer

const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function streamFileDownload() {
  // The example below demonstrates how we can reference a remote file, then
  // pipe its contents to a local file.
  // Once the stream is created, the data can be piped anywhere (process, sdout, etc)
  await storage
    .bucket(bucketName)
    .file(fileName)
    .createReadStream() //stream is created
    .pipe(fs.createWriteStream(destFileName))
    .on('finish', () => {
      // The file download is complete
    });

  console.log(
    `gs://${bucketName}/${fileName} downloaded to ${destFileName}.`
  );
}

streamFileDownload().catch(console.error);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM