【问题标题】:Why the size of my upload file of Cloud Storage Cloud is it "0 bytes" (Node)为什么我的云存储云上传文件的大小是“0字节”(节点)
【发布时间】:2020-08-04 14:53:27
【问题描述】:

我尝试将 pdf 上传到 Google 云存储,但我不知道为什么文件大小为 0 字节...

我已经尝试在 3 天内解决此问题,但我没有回复.. 这是我的代码:

const  cv = request.file('cv')
  
      console.log(cv)
    
        const gc = await new Storage({
          projectId: GOOGLE_CLOUD_PROJECT_ID,
          keyFilename: GOOGLE_CLOUD_KEYFILE,
        })

        const bucked = gc.bucket('rootbusco')
        const file = bucked.file(cv.stream.filename)

         const stream = await cv.stream.pipe(file.createWriteStream({
          resumable: false,
          gzip: true,
          metadata: {
            contentType: cv.stream.headers['content-type']
          }
        }))

        stream.end(cv.stream.data);

感谢提问

【问题讨论】:

    标签: javascript node.js google-cloud-functions google-cloud-storage adonis.js


    【解决方案1】:

    您正在从您的请求文件对象(cv.stream.pipe)创建stream,这是不正确的,您只会在stream.end() 中使用它来实际填写数据,所以如果您更改这部分代码到以下(未经测试的)代码,它应该可以工作:

    const stream = file.createWriteStream({
        resumable: false,
        gzip: true,
        metadata: {
            contentType: cv.stream.headers['content-type']
        }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-22
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-03
      • 2017-01-03
      相关资源
      最近更新 更多