Problem Uploading Image to Appwrite: "Empty file passed to the endpoint" base64
- 0
- Web
- Android
- Storage
- React Native
- Self Hosted
Hello, I’m facing an issue when trying to upload images to Appwrite using React Native, and I need it to work both on web and mobile.
On mobile, I am able to load and send images to Appwrite successfully. However, when trying to send the image via web, I get the error "AppwriteException: Empty file passed to the endpoint."
The process I am using is as follows:
When the user selects an image, I process it as a ProcessedImage object. If the platform is web, the uri is a Base64 string (e.g., data:image/png;base64,...), whereas on mobile the uri is a local file path. I am using the createFile method from Appwrite to upload the file, but since the uri value is Base64 on the web, I’m unsure how to make Appwrite interpret it correctly. What I’ve tried:
I’ve tried converting the Base64 string into a Blob, but I still receive the error on web. I’ve verified that the platform is being correctly identified using Platform.OS, and the upload code is the same for both web and mobile. Question: How can I upload the image to Appwrite, ensuring that it works correctly on both mobile and web, where on web the uri is a Base64 string? Is there a way to convert or process the Base64 so that Appwrite accepts it properly?
Code snippets:
export async function uploadFile(file, type) { if (!file) return;
// Extract MIME type and keep other file properties const { mimeType, ...rest } = file; const asset = { type: mimeType, ...rest }; // Create asset object with type and other properties
try { // Upload file to Appwrite storage const uploadedFile = await storage.createFile( appwriteConfig.storageId, ID.unique(), asset );
const fileUrl = await getFilePreview(uploadedFile.$id, type);
return fileUrl;
} catch (error) { throw new Error(error); } }
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).
soooo you have react native and a separate web app?
Recommended threads
- [SOLVED] What does avatars.getInitials r...
I am using this function and on logging the value i am getting something like `{"_h": 0, "_i": 0, "_j": null, "_k": null}` here is the code i used ```export fun...
- Middleware
how to make middleware in nextjs appwrite with client side auth?
- Error 400: redirect_uri_mismatch
Hi team, Google OAuth was working fine with our Appwrite Cloud setup until yesterday. We did not change any configuration in Appwrite, Google Cloud, or our cod...