为什么我的云存储云上传文件大小是“0字节”(节点)
Why the size of my upload file of Cloud Storage Cloud is it "0 bytes" (Node)
我尝试将 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);
感谢提问
您正在从您的请求文件对象 (cv.stream.pipe
) 创建 stream
,这是不正确的,您只会在 stream.end()
中使用它来实际填充数据,所以如果将这段代码更改为以下(未经测试的)代码,它应该可以工作:
const stream = file.createWriteStream({
resumable: false,
gzip: true,
metadata: {
contentType: cv.stream.headers['content-type']
}
})
我尝试将 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);
感谢提问
您正在从您的请求文件对象 (cv.stream.pipe
) 创建 stream
,这是不正确的,您只会在 stream.end()
中使用它来实际填充数据,所以如果将这段代码更改为以下(未经测试的)代码,它应该可以工作:
const stream = file.createWriteStream({
resumable: false,
gzip: true,
metadata: {
contentType: cv.stream.headers['content-type']
}
})