firebase - base64 图像未正确存储在 firebase 的云存储(又名 firebase 存储)中
问题描述
我正在使用 firebase Web 界面将 base64 图像上传到 firebase(又名 firebase 存储)的云存储。
我用于上传的代码(在 React Native 中)如下:
const ref = await firebase.storage().ref(user).child(curTime.toString());
await ref.putString(base64String, 'base64', { contentType: 'image/jpeg' })
但是,当我尝试查看图像时,它无法显示。
以下是相关代码:
const uploadImageAsync = async(userId, curTime, photoUri) => {
const user = normalizeUserId(userId); // prepare for firebase write
let firebaseImageUrl = null;
let base64String;
try {
base64String = await FileSystem.readAsStringAsync(photoUri,
{ encoding: FileSystem.EncodingTypes.Base64 });
} catch (error) {
console.log(error);
return null;
}
const ref = await firebase.storage().ref(user).child(curTime.toString());
await ref.putString(base64String, 'base64', { contentType: 'image/jpeg' })
.then(async(snapshot) => {
await snapshot.ref.getDownloadURL().then(uploadURL => {
firebaseImageUrl = uploadURL;
}, (error) => { // failed to get uploadedURL location
console.log(error);
return null;
});
}, (error) => { // failed to upload image to firebase storage);
console.log(error);
return null;
});
return firebaseImageUrl;
};
解决方案
推荐阅读
- office-js - Microsoft 的某个人可以写一份关于如何在当今调试 Microsoft-365 应用程序的工作说明(2021 年 8 月后)
- bash - 此脚本中的“<&1”是什么意思“读取 -n 1 k <&1”
- django - 我的 for 循环没有按预期工作 - 数据没有显示在我的 django 模板中
- eclipse-hono - 如何将网络节点的 Eclipse Sparkplug Edge 与 Eclipse Hono 集成
- design-patterns - 以下任何模式或良好做法?调度员、指挥员、协调员?
- powershell - 如何在 PowerShell 中使用自定义颜色创建饼图?
- git - 在 git rebase 期间对帅哥的“交互式审查”
- ruby-on-rails - 我该如何修复这个 MacOS(m1) Ruby Mess
- python - keras 模型,对 c++ 的价值
- c# - 在不同大小的 inkcanvas 之间复制墨水笔划