I'm encountering the following issue:
[Unhandled promise rejection: Invariant Violation: Failed to construct
File
: Must pass bothparts
andname
arguments.]
I am attempting to upload an image to Firebase cloud storage by selecting it on my phone. The URI I am trying to pass looks like this:
file:///Users/miamiamia/Library/Developer/CoreSimulator/Devices/CEC7A0BD-01C0-4929-8CF7-74A7FE34293D/data/Containers/Data/Application/C49F3C42-E858-4612-8088-E578FCABA4D6/Library/Caches/ExponentExperienceData/%2540miamiamia%252Fagain/ImagePicker/164BF9DA-8A20-4C97-A892-CB5A1BB4643D.jpg
What could be the mistake in my approach? I am working with reactnative.
const handleButtonPress = async() => {
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
});
setImageUri(result.assets[0].uri)
console.log(imageUri)
const { uri } = result.assets[0].uri;
// const storageRef = storage.ref();
// const imageRef = storageRef.child('images/image.jpg');
const storageRef = ref(storage, "path/to/image.jpg")
const file = new File([""], uri);
const uploadTask = putFile(storageRef, file)
uploadTask.then((snapshot) => {
console.log("Uploaded a blob or file!");
const downloadURL = getDownloadURL(storageRef);
});
}