最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何从云功能将文件(从URL)上传到Firebase存储中>>

运维笔记admin9浏览0评论

如何从云功能将文件(从URL)上传到Firebase存储中>>

如何从云功能将文件(从URL)上传到Firebase存储中>>

我正在从源API抓取图像并手动替换低质量的条目。因此,我正在寻找执行以下流程(使用WebRequest库):

const download = await WebRequest.get(imageUrl);
const file = new File(download.content, "filename.jpg");  // <-- how to do this?
const filePath = ???  // <-- how to do this?
admin.storage.bucket().upload(filePath, {destination: ..., contentType: "image/jpeg"});

我也尝试过:

const download = await WebRequest.get(imageUrl);
const imageBuffer = Buffer.from(download.content, "base64");
const imageByteArray = new Uint8Array(imageBuffer);
const file = bucket.file(desiredPath);
await file.save(imageByteArray);

[这都是在正常的functions.https.onRequest()处理程序的流程中发生的,但是到目前为止,我还无法弄清楚如何成功地将WebRequest.get的输出操纵为令人满意的bucket.upload()的输入。请注意,正在上传的文件is

-大小仅为原始图像的两倍,并且已损坏,因此无法作为图像查看。任何帮助将不胜感激!

非常感谢!

我正在从源API抓取图像并手动替换低质量的条目。因此,我正在寻找执行以下流程(使用WebRequest库):const download = await ...

回答如下:

根据我在网络请求示例中看到的,download.content只是一个字符串。如果要使用节点SDK将字符串上传到Cloud Storage,则可以使用File.save,直接传递该字符串。

发布评论

评论列表(0)

  1. 暂无评论