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
- How to use dart workspaces to deploy a f...
Hello, I'm developing a Flutter application and I would like to leverage dart pub workspaces to deploy a function with a dart runtime as advertised here : http...
- Migration from Cloud to Self-Hosted not ...
Hello Appwrite Community, I've got the problem, that when I try to migrate my Appwrite Project from the cloud to my self-hosted Appwrite, that an API Key is mi...
- I can't migrate my project from Appwrite...
I'm having an issue migrating my Appwrite project to a self-hosted instance. The problem is that I've exceeded my read rate limit (or database read limit), so I...