如何从云功能将文件(从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,直接传递该字符串。