【发布时间】:2021-04-26 14:04:43
【问题描述】:
我正在使用相机(react-native-image-Picker)进行挑选并将其保存到存储中。 这是我的做法。
const saveImage = async () => {
const id = firebase.firestore().collection('food').doc().id
const storageRef = firebase.storage().ref()
const fileRef = storageRef.child(file.fileName) //name of image to store
await fileRef.put(file) //store image
firebase.firestore().collection("food").doc(id).update({
image: firebase.firestore.FieldValue.arrayUnion({
name: file.fileName,
url: await fileRef.getDownloadURL()
})
})
}
console.log(typeof file);
gives => "object"
console.log(file);
//gives =>
file = {height: 2322,
uri:"content://com.photodocumentation.imagepickerprovidlib_temp_7a0448df-1fac-4ac7-a47c-402c62ecce4c.jpg",
width: 4128,
fileName: "rn_image_picker_lib_temp_7a0448df-1fac-4ac7-a47c-402c62ecce4c.jpg",
type: "image/jpeg"}
结果: 在 Firebase(存储)中,图像被保存为 application/octet-stream 而不是 image/jpeg。 图片未显示,从存储下载时显示未定义。
任何帮助将不胜感激。
【问题讨论】:
标签: javascript firebase react-native firebase-storage react-native-image-picker