【发布时间】:2020-04-08 19:09:30
【问题描述】:
我正在尝试将给定的结果(图片的 URL)下载到谷歌云存储。
代码在 firebase 函数中运行,由 pub/sub 触发。
使用 unsplash API 的一切工作正常,for 循环也在循环,但它不会将图像保存到云存储或抛出任何错误。我不知道可能是什么问题。
// Search Photos on Unsplash
unsplash.search.photos('searchTerm', 1, 5, { orientation: "landscape" })
.then(toJson)
.then(async res => {
const images = res.results;
for (const image of images) {
await fetch(image.urls.raw)
.then(result => {
// The Part that is not working
result.body.pipe(storage.bucket('bucket-id.appspot.com/').file(image.id+".jpg").createWriteStream());
return true;
});
}
});
【问题讨论】:
-
你试过用upload()代替createWriteStream吗?
标签: node.js async-await google-cloud-functions google-cloud-storage firebase-storage