
// Preparing the file `const setImageToCloud = async () => { setLoading(true); try { // Determine MIME type based on file extension if (!selectedImage) { throw new Error("No image selected"); }
const response = await fetch(selectedImage.uri); // fetch the local file
const blob = await response.blob(); // get file data as Blob
const fileObj = new File([blob], "photo.jpg", { type: blob.type });
// Now upload to Appwrite:
const res = await createFile({ file: fileObj! });
if (res.success) {
console.log("Image uploaded successfully");
setHideDrawer(true);
setImage(selectedImage?.uri!);
} else {
console.log("Image upload failed");
Alert.alert("Image upload failed");
}
} catch (error) {
console.log("Error uploading image", error);
Alert.alert("Error uploading image");
} finally {
setLoading(false);
}
};`
// For uploading the file to Appwrite `export const createFile = async ({ file }: { file: any }) => { try { const result = await storage.createFile( appwriteConfig.storageBucketOneId!, ID.unique(), file )
console.log("File created:", result);
return { success: true }
} catch (error) {
console.log("Error creating file:", error);
return { success: false };
}
}`
Recommended threads
- Realtime Disconnects and Error: INVALID_...
Hi Support, we are still experiencing the issue and we are a subscriber on your platform under the account of charlesbcalague@gmail.com I just want to ask here...
- Having Some Trouble With Getting Started
Hi everyone. I'm having some issues with the initial setup of AppWrite for my React Native mobile app. I've done step 1 and 2, but when it comes to step 3, I op...
- SSO google apple not working anymore
We use Apple and Google sso in our react native app. Everything worked fine until we noticed today that we see general argument error. We did not change anythi...
