简体   繁体   English

Firebase的云功能图像下载功能错误

[英]Cloud Functions for Firebase Image download function Error

I am building a web application using Firebase and the new feature Cloud Functions for Firebase. 我正在使用Firebase和Firebase的新功能Cloud Functions构建Web应用程序。 I have created a function that takes a URL and downloads the image into a 64-bit encoded string as below using the node modules request and request-promise-native: 我创建了一个函数,该函数使用一个URL,并使用节点模块request和request-promise-native将图像下载为64位编码的字符串,如下所示:

module.exports = {
downloadImageFromUrl: function (url) {
    var options = {
        method: 'GET',
        uri: url,
        resolveWithFullResponse: true,
        simple: false,
        family: 4
    };
    return rp.get(options)
        .then(function (res) {
            return "data:" + res.headers["content-type"] + ";base64," + new Buffer(res.body).toString('base64');
        })
        .catch(function (error) {
            console.log("ERROR GETTING image", error);
            return error;
        });
    }
};

The top function works perfectly running locally but once on firebase it gives the error: 顶部函数可以在本地完美运行,但是一旦在Firebase上运行,它就会出现错误:

RequestError: Error: getaddrinfo EAI_AGAIN lh6.googleusercontent.com:443
at new RequestError (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/user_code/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/user_code/node_modules/request/request.js:188:22)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.onRequestError (/user_code/node_modules/request/request.js:884:8)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at connectErrorNT (net.js:1020:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)

I am calling the function in the firebase auth trigger when a user is created as below: 如下创建用户时,我正在firebase auth触发器中调用该函数:

exports.createUser = functions.auth.user().onCreate(event => {
    if (event.data.photoURL) {
    utils.downloadImageFromUrl(event.data.photoURL)
        .then(function(res){
            console.log("User Photo", res);

        })
        .catch(function(error){
            console.log("Error", error);
        })
}
});

Any help would be greatly appreciated. 任何帮助将不胜感激。

Not entirely sure yet if this is the answer, but after reading the documentation, I read their free plan which says you cannot make any out bound requests. 尚不完全确定这是否是答案,但是在阅读了文档之后,我阅读了他们的免费计划,该计划说您不能提出任何超出范围的请求。 So I guess getting an image from a Url counts as an outbound request. 因此,我想从Url获​​取图像算作出站请求。 After I start paying for their service, I will come back to verify if this was the problem. 开始为他们的服务付款后,我将再次确认是否是问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM