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
- Invalid token passed in the request
Hello, I have an issue using updateMagicURLSession. I send the email using sendMagicLink, which works fine. When i click the link in the email i get the invali...
- functions domain error
I cannot set up the domain for function I’m trying to add the domain api.example.com I can only use Cloudflare as the DNS provider because my domain provider do...
- Storage Bucket Permissions
Hey folks, when enabling CRUD on the bucket level for the role any, should the bucket be accessible when using a session client?