// 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
- React Native/iOS platform integrations h...
Anyone else have this issue where platform identifiers have been lost/wiped and no option/field available to update them in the console?
- Issue with Appwrite Read Request Limit b...
Hi Team, My coding terminal connected to the Appwrite CLI blew through my Projects Read request limit with in a day! and thats a large limit! I'm not sure how...
- Sub-minute server-side execution for rea...
Hey — I'm building a real-time auction app on Appwrite Cloud and running into a timing limitation I'd please love some clarity on. My use case: when a bidding ...