#Transmit large array to function
52 messages ยท Page 1 of 1 (latest)
array length is 5054 and the chars are greater then 8192. How I can sent more chars?
You'll probably need to use some zip solutions, check if this ๐ is helping you.
Pako.js would be very useful if you're using js-functions
https://github.com/nodeca/pako
This is a demonstration of how it should go.
In your **client **side
const pako = require('pako');
const {toBase64, fromUint8Array} = require('js-base64');
const data = { my: 'function', data: [1, 2], so: 'big!!!!' };
const compressed = pako.deflate(JSON.stringify(data));
const string = toBase64(fromUint8Array(compressed));
await functions.createExecution('F_ID', string);
In your **server **JS function
const pako = require('pako');
const {fromBase64, toUint8Array} = require('js-base64');
const bytes = toUint8Array(fromBase64(req.payload ?? '');
const restored = JSON.parse(pako.inflate(bytes, { to: 'string' }));
server-side im using .js
client-side .ts
I guess I can use ths: https://www.npmjs.com/package/@types/pako
okay, thanks
const compressed = pako.deflate(JSON.stringify(data));
return await this.appwrite.functions.createExecution(functionId, compressed);
The argument of type "Uint8Array" cannot be assigned to the parameter of type "string".
this error cames for compressed in functions.createExecution(functionId, compressed)
I've update the snippet, try now.
stringData looks like that:
that is the latest code:
const compressed = pako.deflate(JSON.stringify(data));
const stringData = new TextDecoder().decode(compressed);
console.log(stringData)
return await this.appwrite.functions.createExecution(functionId, stringData, async);
same error
Yep, sorry
Let me run it once on my function.
AppwriteException: Invalid data: Value must be a valid string and at least 1 chars and no longer than 8192 chars
AppwriteException: Invalid data: Value must be a valid string and at least 1 chars and no longer than 8192 chars
That is my data what i want to try to submit to my appwrite function
Done
ckecking
unfortunately still the same error.
const compressed = pako.deflate(JSON.stringify(data));
const stringData = toBase64(fromUint8Array(compressed));
return await this.appwrite.functions.createExecution(functionId, stringData, async);
Using this shrinked a 20K characters to just 4K nad was able to go the function
Can you share the payload data?
of corse
In network tab
Mmm, this one is 20K long
Meaning is more then the 8192 chars limit.
yes chatgpt says 10K ๐
With this amount of data you'll need to choose a different approach
You'll need to use the Appwrite Storage module.
- Upload the file to storage using
createFilehttps://appwrite.io/docs/server/storage?sdk=web-default#storageCreateFile - In the function fetch the file using
getFilehttps://appwrite.io/docs/server/storage?sdk=web-default#storageGetFile - Then, just delete it https://appwrite.io/docs/server/storage?sdk=web-default#storageDeleteFile
Or
Okay, I feared that ๐
I tried to find a solution without storage.
You can dived the Base64 string into 8000 chars chunks, then in the function you can try do maybesomthing like this
for(let chunk in chunks){
await this.appwrite.functions.createExecution(functionId, JSON.stringify({lastChunk: false, chunk: chunk }), async);
}
It's possible but will require some extra work from your side.
And its actually good option if you want to avoid storage.
but thanks for your help. I will try to split the array into chunks less hen 8000 chars. If i find something. I can share it with you
๐
But why is there a limitation from appwrrite. Do you know it?
Probably against abuse
hmm, okay. but for self host there should be a option to change the limitations. but its okay. We can find something
You are on self host?
If you want to change it in a self-hosted one, you'll need to edit these two lines
https://github.com/appwrite/appwrite/blob/master/app/executor.php#L462
https://github.com/appwrite/appwrite/blob/master/app/controllers/api/functions.php#L1025
In order to edit and leave your Appwrite up to date, like you can see here
#1120778518360498276 message
Also check this
#1115191629733703730 message
#1115191629733703730 message
Change it to let's say 100000
You can still use the zip choice to get shorter upload times.
nice, I will try that definitly. Big thanks. That would help. I will keep you up-to-date
the response payload is also limited. It trims in the and that affacting the large object. That means the response payload cuts after some limit. You know in the code where to change it?
What error do you get?
Any time you see this line
\mb_strcut($res, 0, 1000000), // Limit to 1MB
Like in here https://github.com/appwrite/appwrite/blob/master/app/executor.php#L578
It's when the limit of the response is set 1MB, just change it to whatever number you like.