【发布时间】:2020-01-04 17:49:35
【问题描述】:
我已将用户图库中的图片上传到 Firebase 存储并获得以下 URL -
在谷歌浏览器上打开时是一个有效的图像 URL。
问题是,当我尝试通过以下方法将其发送到 Firebase 服务器时,我的来自 firebase 的 URL 不起作用 -
exports.helperPromiseNotify = function (profileId, notificationKey, body, payloadData, image) {
// admin
const fcm = admin.messaging();
const db = admin.database();
// prepare obj
const notificationDBObj = {
created_at: internalGetUnixEpoch(),
is_read: false,
key: notificationKey,
body: body,
data: payloadData,
};
console.log("utils.js helperPromiseNotify " + image)
var payload = {
notification: {
body: body,
image: image
//this is the place -> //image: "https://1mdtalent.com/wp-content/uploads/2017/12/cropped-1-2.png" // <- this is the place
},
data: payloadData
};
// find
const prFetchDeviceTokens = db.ref(config.ENTITY_NAME_DEVICES).child(profileId).child("tokens")
.once("value")
.then(snapshot => {
const tokensArr = new Array();
if (snapshot.exists()) {
// extract tokens
const obj = snapshot.val();
Object.keys(obj).forEach(key => {
tokensArr.push(obj[key]);
})
}
return tokensArr;
})
const prSendFCM = tokensArr => {
if (tokensArr !== undefined && tokensArr !== null && tokensArr.length > 0 && tokensArr.length <=1000) {
fcm.sendToDevice(tokensArr, payload)
.catch((error) => {
console.log(`Failed send notification to device: ${error}`);
});
}
};
// chains
const prDB = db.ref(config.ENTITY_NAME_NOTIFICATIONS).child(profileId).push(notificationDBObj);
return prDB
.then(() => prFetchDeviceTokens)
.then(tokensArr => prSendFCM(tokensArr));
}
我有从谷歌获取的另一张图片,它有一个更清晰的 URL 和一个扩展名,所以我想这就是问题所在。当将“图像”变量从当前运行的变量切换到注释中的变量时,它可以工作,这意味着它不是逻辑问题,而是 Firebase 服务器无法使用的 URL 问题
我正在尝试弄清楚 firebase API 真正期望的是什么,我的 Firebase 中的 URL 缺少什么以及如何将其添加到其中。
【问题讨论】:
标签: javascript android firebase firebase-cloud-messaging firebase-storage