Has anyone successfully deployed a function that returns binary data, such as an image/png or audio/wav? I have with other functions had to base64 encode / decode etc, but want to avoid this due to the size and compute required for my application function. I just want the functions to return the binary data as provided to appwrite by my function. Currently running self hosted, latest 1.7.4 version. Its a simple python 3.12 deployed appwrite function that just returns the raw binary data and content-type of audio/wav, very much like the docs for functions that returns an image/png if you request a type of binary. The documentation shows doing almost exactly the same thing I'm doing where I'm opening the binary file and returning the bytes.
python code, tried each of the following:
return context.res.binary(wav_file_bytes})
return context.res.binary(wav_file_bytes, 200, {"content-type": "audio/wav"})
return context.res.binary(wav_file_bytes, 200, {"content-type": "audio/wav; charset=ISO-8859-1"})
The last one because the python 3.x open-runtimes insist on adding '; charset=utf-8' to any content-type that does not begin with 'multipart/' and I thought this was triggering the error.
The actual executions page successfully shows a 200 status code for the function's returned result, but once Appwrite internally processes the result, it has an error due to trying to then json decode that data.
The following error in 'appwrite' logs:
[Error] Method: POST
[Error] URL: /v1/functions/:functionId/executions
[Error] Type: JsonException
[Error] Message: Malformed UTF-8 characters, possibly incorrectly encoded
[Error] File: /usr/src/code/src/Appwrite/Utopia/Response.php
[Error] Line: 825
I can see why its complaining because an audio/wav (or png or many other binary file types!) will contain data that is not valid utf-8.
How is an Appwrite (python) function supposed to return binary data to stop Appwrite further trying to process it and encode it wit utf-8?
Recommended threads
- FCM Message error
When creating a message target via flutter sdk via ``` final target = await _account.createPushTarget( targetId: targetId, identifier: deviceTok...
- Bulk API limitations in self-hosted serv...
Environment: Appwrite Selfhost SDK: node-appwrite 28.0 Calling `upsertRows` (also applies to `createRows`/`updateRows`/`deleteRows`) with more than 100 rows fa...
- Self Hosted GitHub connection not adding...
After upgrading to 1.9.6 i noticed that i cannot search for new repositories when trying to add new functions. I removed the existing github connection via Set...