Skip to content
Back

What's the correct way to send a file to a function?

  • 0
  • Functions
memoonlite
9 Sep, 2025, 12:11

Hello everyone! 😊

I have a hard time figuring out the right way to send a file to an Appwrite function.

Lets say I have an image that I'd like to pass to a function, alongside a description of the file. Should I just pass it like this?

Dart: ``Uint8List pngBytes = await fetchPngBytes('');

final execution = await appWriteClientController.function.createExecution( functionId: 'upload-file, body: jsonEncode({ 'description': 'A test file', 'file': pngBytes, }));``

I also notice people encode the file to base64 first and pass that to the function. Is that a better way to pass the file?

Another thing I read is that 'Accept: multipart/form-data' should be passed to createExecution when a file is passed to a function. Is this correct?

The function side is also a bit unclear to me:

node.js: const file = req.bodyBinary; if (!file) { return res.json({ success: false, message: 'No file received' }); } else { return res.json({ success: true, }); }

Is this the right way to retrieve the file in my function? πŸ€”

TL;DR
Developers are unsure how to pass a file to an Appwrite function. They wonder if it's best to encode the file to base64 or pass it directly. In the function, the file is accessed using 'req.bodyBinary'. It's recommended to encode the file to base64 before sending it to the function, and 'Accept: multipart/form-data' should be passed when sending a file to a function.
Guille
9 Sep, 2025, 12:46

Hey, check this post with the same question: https://discord.com/channels/564160730845151244/1157683118782816328

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