Google Cloud Storage文件写入流失败 [英] Google Cloud Storage file write stream fails

查看:144
本文介绍了Google Cloud Storage文件写入流失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用node.js在Google云存储中写入文件.

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();

我正在使用节点8.3.0,npm 5.4.1,@ google-cloud/storage 1.3.0

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

推荐答案

好的,我似乎已经解决了我的问题;您遇到的相同问题.我收到此错误消息是因为我的文件名包含破折号".从文件名中删除后,它成功上传且没有任何错误.祝你好运!

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!

这篇关于Google Cloud Storage文件写入流失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆