Skip to content
Init is coming / May 19 - 23
Back

ERROR Create file error, uploadImage: [TypeError: Cannot read property 'size' of undefined]

  • 0
  • React Native
  • Storage
S
24 Jan, 2025, 19:43

Hi, I am using React-native and appwrite for my project. I am trying to upload an image to Appwrite storage bucket but receiving error while creating and uploading the file. ERROR Create file error, uploadImage: [TypeError: Cannot read property 'size' of undefined]. Please help me with correct approach to store the image to bucket. The code I am using is provided below and frontend and console response is attached in the file.

Backend.js const uploadImage = async (imagefile) => { if (!imagefile) { console.error('No file provided for upload.'); return; }

console.log('File to Upload:', imagefile);

const asset = { name: imagefile.fileName, type: imagefile.type, size: imagefile.fileSize, uri: imagefile.uri, }; console.log('Prepared File for Upload:', asset); try { const uploadedFile = await storage.createFile( BUCKET_ID_IMAGE, ID.unique(), asset, ); console.log('Uploaded file:', uploadedFile);

TypeScript
return uploadedFile;

} catch (error) { console.error('Create file error, uploadImage:', error); throw error; } };

TL;DR
Developers are facing an issue when trying to upload an image to an Appwrite storage bucket. The error "TypeError: Cannot read property 'size' of undefined" is occurring during file creation and upload. The provided code in 'Backend.js' shows the implementation for uploading the file. The problem appears to be with the 'imagefile' object not having the expected properties. Check the 'imagefile' object to ensure it contains the necessary properties like 'fileName', 'type', 'fileSize', and 'uri' before attempting the upload process.
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