Node.js Google-云存储上传目的地规范

Node.js Google-cloud storage upload destination specification

我有一个 Node.js 服务器,我正在使用 google-cloud 包将一些图像文件上传到 Firebase 存储

上传本身工作正常,但 google-cloud API 似乎只能将文件上传到 Firebase 存储根文件夹。

有什么方法可以指定上传图片的远程位置吗?

我现在在做什么:

const serviceAccount = require('./serviceAccount.json');

const storage = gcloud.storage({
   projectId: '*projectId*',
   credentials: serviceAccount
});

const storageBucket = storage.bucket('*bucket*');

storageBucket.upload(localFsPath)
   .then(data => /* Some stuff */)
   .catch(err => console.log(err));

有没有办法做这样的事情?

storageBucket.upload(path, { destination: 'a/b/c/file.jpg' })
   .then(data => /* Some stuff */)
   .catch(err => console.log(err));

正如@Jérôme 指出的那样,该方法是正确的。我忽略了目标路径字符串的错误格式,即“/x/y//z”。

明显有2个错误

首先,路径不能以'/'开头,而是节点名称(file/folder)。

第二个问题('//'部分)有趣的是没有导致 API 抛出,而是导致 Firebase 递归地创建 endless 节点嵌套结构(文件夹)名为“/”。