4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

画像のURLから画像ファイルを取得してFirebase Storageに保存する例

Posted at

画像の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);
    }
};
4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?