Hi. I'm trying to make a function which get image on 3rd party service and send it back to the user in base64 string. And issue seems like base64 string brakes response object. Appwrite runs locally on MacOS.
My functions return response:
res.json({ success: true, imageBase64: 'base-64-string'});
client side handler:
if (execution.statusCode !== 500) {
console.log('response ::: ', execution.response.image)
setImageData(execution.response.image);
}
and console log output is:
{"success":true,"image":"iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAAAaGVYSWZNTQAqAAAACAACknwAAgAAACkAAAAmkoYAAgAAABgAAABQAAAAAE9wZW5BSS0tZjE4ZWQ5NzYxYjE2NW... Show more (1Mb) Copy
and can not be parsed. On client side I used React.js if it matters.
In case return object doesn't contain so long string as base65 image it parsed fine and I can get access to values by key in JS.
Any suggestion will be really appreciated.
Btw, response is a string, not object π§
Probably yes, but I can get access to for example, response.success in case when return not so much data
Btw, if it returns a string why there are 2 types of response: res.send and res.json?
On the open runtimes (function side) res.json will automatically serialize. Appwrite side does not automatically deserialize
You can get the response.success after parsing the string with like JSON.parse, right?
Sure, just wonder why I have not to do this if response body short so I can access it directly without deserialization. But it my case Iβve tried to parse response and no success. Message was regarding unexpected string end or something like that. Iβm assuming itβs because of long base64 string, more than 10000 characters
What version of Appwrite are you on? You should need to deserialize it if it's working successfully π§
Large responses don't work for functions. There's a limit of 4MB or something so your data might be truncated. For files, you should really use the storage API
I have to check if my response is more than 4Mb. Do you have the exact limitation?
Iβll check sizes of my files then and get back later
@Steven you are right, my files are 2Mb average so sending base64 withing responss object not a good idea. Thanks for the clue. And I belive this limitation should be highlited in the docs.
It's documented here but it's outdated: https://appwrite.io/docs/models/execution. The limit used to be smaller
Ahh, missed it. Gone through Guides section and missed it π§
π¬ What is it now? Lemme go update
1mb, but will probably change in the next release
[RESOLVED] Function response with base64 image
[SOLVED] Function response with base64 image
Recommended threads
- Having issues with login via CLI
``` ~/appwrite ξ° appwrite login --endpoint https://localhost/v1 --verbose ? Enter your email myvalidemai...
- delete document problems
i don't know what's going on but i get an attribute "tournamentid" not found in the collection when i try to delet the document... but this is just the document...
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...