Upload image from URL to Firebase Storage

后端 未结 4 2299
慢半拍i
慢半拍i 2020-12-03 06:26

I\'m wondering how to upload file onto Firebase\'s storage via URL instead of input (for example). I\'m scrapping images from a website and retrieving their URLS. I want to

4条回答
  •  庸人自扰
    2020-12-03 06:37

    Javascript solution to this using fetch command.

    var remoteimageurl = "https://example.com/images/photo.jpg"
    var filename = "images/photo.jpg"
    
    fetch(remoteimageurl).then(res => {
      return res.blob();
    }).then(blob => {
        //uploading blob to firebase storage
      firebase.storage().ref().child(filename).put(blob).then(function(snapshot) {
        return snapshot.ref.getDownloadURL()
     }).then(url => {
       console.log("Firebase storage image uploaded : ", url); 
      }) 
    }).catch(error => {
      console.error(error);
    });
    

提交回复
热议问题