
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
- Failed to connect to exc1 on deploy
Hi, i just came across this yesterday and it worked like a charm on selfhosting on my personal windows machine because im testing everything. But now, on Appwri...
- How to save or backup my project in self...
I'm looking for a tutorial on how to backup my project and how to import it.
- Little UI problems on 1.7.4 on self-prem...
I'm using 1.7.4 on self-prem and on cloud and i'm seeng several UI differences. It happens on ALL my self-prem instances, new and migrated This is a clone, sam...
