我正在尝试将图像上传到我的Firebase,但我无法弄清楚。
这是我的代码
_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1
});
if (!result.cancelled) {
this.uploadImage(result.uri, 'test-image')
.then(() => {
console.log('it work')
})
.catch(error => {
console.log('it does not work')
console.error(error)
})
}
};
uploadImage = async (uri, imageName) => {
const response = await fetch(uri);
const blob = response.blob();
const ref = firebase.storage().ref().child(`images/${imageName}`);
return ref.put(blob);
}
我遇到此错误。
FirebaseStorageError {
"code_": "storage/invalid-argument",
"message_": "Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File.",
"name_": "FirebaseError",
"serverResponse_": null,
}
尝试用var ref= firebase.storage().ref().child('images/'+imageName)
代替您的