Skip to content
Back

PROBLEMS UPLOADING IMAGE IN REACT-NATIVE TO STORAGE ON APPWRITE

  • 1
  • Databases
  • React Native
  • Storage
  • REST API
Emmachris
8 Mar, 2025, 20:31

having serious problems uploading image from react-native using expo-go to Appwrite storage. #react-native #storageupload #createfile

TL;DR
Developers are encountering issues uploading an image to storage in a React Native app using Appwrite. The error indicates that the file's size is undefined. The problem lies in trying to access properties such as `name` of `fileUri`. The solution is to ensure `fileUri` contains the required properties (`name`, `fileSize`, `mimeType`, `uri`) before passing it to `createFile` function in Appwrite storage. Additionally, it's recommended to use backticks to format the code.
Steven
8 Mar, 2025, 21:46

Can you provide details about what you're doing? And what problem are you having?

Also, what package did you install?

D5
9 Mar, 2025, 00:00

And what's the code?

Emmachris
9 Mar, 2025, 18:40

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;

Emmachris
9 Mar, 2025, 18:41

next is the part of my appwrite code responsible for this;

Emmachris
9 Mar, 2025, 18:42

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 };

TypeScript
// 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); } };

Steven
9 Mar, 2025, 18:42

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).

Emmachris
9 Mar, 2025, 18:44

alright sir

Emmachris
9 Mar, 2025, 18:48

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

Steven
9 Mar, 2025, 19:00

What Appwrite package did you install?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more