我遇到的问题与此相反:使用 Cloud Functions for Firebase 和 @google-cloud/storage 删除图像时出现问题 https://stackoverflow.com/questions/43178152/issues-deleting-an-image-using-cloud-functions-for-firebase-and-google-cloud-st
(为了记录,我已经尝试了那里建议的所有事情)。
基本上我有一个已知的文件路径,然后是由数据库事件触发的云函数。
我可以初始化一个存储桶,获取一个文件及其名称,但是当我尝试下载它时,我收到 API 错误:未找到。
这是我的代码:
module.exports = (orgID, reportID) => {
const bucket = gcs.bucket("MY_PROJECT.appspot.com");
const filePath = `/safety_hotline/${orgID}/${reportID}`;
const file = bucket.file(filePath);
// the name is shown correctly in the console
console.log(file.name);
const tempLocalFile = path.join(os.tmpdir(), filePath);
const tempLocalDir = path.dirname(tempLocalFile);
return mkdirp(tempLocalDir)
.then(() => {
// Download file from bucket.
return file.download({ destination: tempLocalFile });
})
.then(() => {
console.log("file downloaded succesfully");
})
.catch(err => {
console.log(err);
});
}
你可以看到我得到了文件名的控制台日志,所以我不明白为什么我不能下载它?
任何建议都会很棒,谢谢!
编辑:为了清晰起见,对代码进行了一些编辑
我看到你有这一行:
const filePath = `/safety_hotline/${orgID}/${reportID}`;
我猜您可能已经用以下模式命名了您的对象safety_hotline/org/report
,但正如上面所写,对象名称的第一个字符将是斜杠。这也是一个合法的对象名称,但通常是无意的。尝试删除斜线?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)