【发布时间】:2020-09-30 05:13:57
【问题描述】:
我正在尝试执行一个简单的 .docx 文件信息下载缓冲区,以便稍后在我的云函数中处理它。我一直在为多个项目使用整个 Google 平台,但从来没有遇到过在服务器端下载的需要,现在我需要,但我不能。
以下代码不起作用,它只是发送超时作为响应(如果我尝试捕获它,我什至不会收到错误消息):
var bucket = admin.storage().bucket("gs://myBucket.com");
return bucket.file("001Lineales/4x3-1/1000.docx").download().then((contents)=>{
var buffer = contents[0];
//I never get into this point
}).catch((error)=>{
//No error
})
我尝试使用本地 NodeJs 脚本并按预期工作。还尝试执行readStream() 下载但没有运气,该功能在任何尝试下载文件时都会挂起。
return new Promise((resolve,reject)=>{
var archivo = bucket.file(selectedCategory).createReadStream();
var array = [];
//Under here, never happens
archivo.on('data', (d) => {array.push(d)}).on("end",()=>{
var newbuff = Buffer.concat(array);
resolve(newbuff)
})
})
文件的读/写权限是公开的。主要问题是调试很困难,因为我无法在本地模拟器中执行此功能。
我能做什么?提前致谢。
编辑:
使用模拟器再次检查本地通话,我收到以下错误:
Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.
【问题讨论】:
-
你能分享你的依赖吗? (package.json 文件)
标签: google-cloud-functions google-cloud-storage