【问题标题】:Python: Is it possible to upload images to Firebase Storage using an image URL and not the image file?Python:是否可以使用图像 URL 而不是图像文件将图像上传到 Firebase 存储?
【发布时间】:2019-09-11 06:14:59
【问题描述】:

我正在尝试使用 Python、Reddit API 和 Firebase 将来自 reddit 的图像存储在 Firebase 存储中,然后将来自 firebase 存储的 URL 放入文档中。

现在我只是将 reddit api 提供的 URL 存储在我项目的 Firebase 数据库中。但这是一个问题,因为有时这些 URL “变坏并过期”意味着当我抓取一个文档并显示我存储的 URL 时,我得到一个错误。

这就是我在 firebase 中创建文档之前获取信息的方式

function getJSON(sub){
    var ret;

    var yourUrl="https://www.reddit.com/r/"+sub+".json";

    fetch(yourUrl).then(response => {
        return response.json();
    }).then(function(data){
        var i = 5;
        list= data.data.children
            curlist = list[i].data
            if(curlist.domain==='i.redd.it'){
                if(curlist.post_hint==='image'){
                    var url =curlist.url;
                    var author=curlist.author;
                    var time=curlist.created_utc;
                    var score = curlist.score;
                    sendToFirebase(url,author,sub,time,score);
            }

            }
    }).catch(err => {
    });
}

我想要做的不是将 reddit URL 放入文档中,而是获取此 reddit URL 并将位于此 URL 末尾的图像存储在我的 Firebase 存储中,这样我就可以获取图像 URL存储在 Firebase Storage 中并放入文档中。

【问题讨论】:

  • 您必须在本地从 URL 下载文件,然后将其上传到 Cloud Storage。

标签: python firebase firebase-storage


【解决方案1】:

Firebase SDK 要求图像数据在本地客户端上可用,才能将其上传到 Cloud Storage。没有将数据的外部图像 URL 上传到 Cloud Storage 的方法。

如果图像不是客户端本地的,您首先需要将其下载到客户端,然后再使用 Firebase SDK 将其上传到 Cloud Storage。

【讨论】:

    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 2016-12-09
    • 2019-08-09
    • 2021-07-03
    • 2015-07-15
    • 2017-09-25
    相关资源
    最近更新 更多