RetroNoodleOriginal post
React Developer
Here is my code:
const uploadImage = async (uri) => {
try {
console.log("Uploading file from URI:", uri);
const fileId = ID.unique();
console.log("Uploading file with ID:", fileId);
const uploadedFile = await storage.createFile(
APPWRITE_BUCKET_ID,
fileId,
uri
);
console.log("Uploaded file:", uri);
return fileId;
} catch (error) {
console.error("Error in uploadImage:", error);
throw new Error("Failed to upload image: " + error.message);
}
};
So that catch never fires, it returns the fileId to the calling function, as if everything worked, but no file shows in the console.
I'm using the react-native specific appwrite libs.
Summary
Developers are having trouble with uploading a file using React Native Expo, receiving no error but not finding the uploaded file. The log errors appear to be unrelated. The issue might be that the code is returning the fileId without confirming the file upload. To solve this, check if the file is successfully uploaded after calling `storage.createFile()` before returning the fileId.