PROBLEMS UPLOADING IMAGE IN REACT-NATIVE TO STORAGE ON APPWRITE
- 1
- Databases
- React Native
- Storage
- REST API
having serious problems uploading image from react-native using expo-go to Appwrite storage. #react-native #storageupload #createfile
Can you provide details about what you're doing? And what problem are you having?
Also, what package did you install?
And what's the code?
Alright sir, i am making an app and there is a part to editStore, now i want to be able to upload picture to storage for coverimage and profile picture, i am using reactnative and expo, also i am making use of appwrite, below is my code below, i'll first post the EditStore.jsx in which is the page i use to change the picture;
next is the part of my appwrite code responsible for this;
export const uploadFile = async (fileUri) => { try { console.log("Uploading file:", fileUri); console.log(fileUri); // Ensure file exists const fileInfo = await FileSystem.getInfoAsync(fileUri); if (!fileInfo.exists) { throw new Error("File does not exist at given URI."); } console.log(fileUri.name); const fileInf = { name: fileUri.name, size: fileUri.fileSize, type: fileUri.mimeType, uri: fileUri.uri };
// Upload to Appwrite storage
const uploadedFile = await storage.createFile(
Config.storageId,
ID.unique(),
fileInf // Pass the File object
);
console.log("File uploaded successfully:", uploadedFile);
return uploadedFile.$id;
} catch (error) { console.error("Upload error:", error.message); throw new Error("Upload failed: " + error.message); } };
export const getFilePreview = async (fileId) => { try { return storage.getFilePreview(Config.storageId, fileId, 2000, 2000, "top", 100); } catch (error) { throw new Error("Failed to get image URL: " + error.message); } };
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).
alright sir
so in my code, the place currently giving me issue is from the uploading to storage aspect, in storage.createFile, its saying cannot read size of undefined and console.log(fileUri.name) does not log anything, it logs undefined
What Appwrite package did you install?
Recommended threads
- Migration from cloud to self-hosted fail...
Hi! I'm trying to migrate a small project from the cloud to a self hosted instance to play around but without any success! The migration process fails with the ...
- Transaction Error
AppwriteException: Transaction with the requested ID could not be found. at Generator.next (<anonymous>) { code: 404, type: 'transaction_not_found', r...
- getFilePreview , getFileView , getFileDo...
I am on Appwrite self hosted 1.8.0 I use the web sdk 21.3.0 I created a bucket and it has this permission (users:create) then i enabled the file security then ...