I'm trying to upload an Image to my firebase but I can't figure it out.
This is my code
_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);
}
I'm getting this error.
FirebaseStorageError {
"code_": "storage/invalid-argument",
"message_": "Firebase Storage: Invalid argument in `put` at index 0: Expected Blob or File.",
"name_": "FirebaseError",
"serverResponse_": null,
}
Use this code:
`const blob = await response.blob();`
Instead of:
const blob = response.blob();
to solve your issue.
尝试var ref= firebase.storage().ref().child('images/'+imageName)
而不是你的
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.