画像のURLから画像ファイルを取得してFirebase Storageに保存する例
Node.js, How to store Image from URL to Firebase Storage?
https://stackoverflow.com/questions/52661914/node-js-how-to-store-image-from-url-to-firebase-storage
への回答の例
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const request = require('request')
admin.initializeApp();
# 略
const getImageFromUrl = async (imgURL) => {
const imgURL = "https://2017.brucon.org/images/b/bc/Twitter_logo.jpg";
const ary = imgURL.split('?')[0].split('/');
const imageName = ary.slice(-1)[0]
try {
const newFile = storage.bucket().file(imageName);
const blobStream = newFile.createWriteStream({ metadata: "image/jpg" });
await request(imgURL).pipe(blobStream);
} catch (error) {
console.log(error);
}
};