#Transmit large array to function

52 messages ยท Page 1 of 1 (latest)

arctic surge
#

I try to transmit a large array via function. I get this error:

function:  AppwriteException: Invalid data: Value must be a valid string and at least 1 chars and no longer than 8192 chars

How I can solve this problem?

#

array length is 5054 and the chars are greater then 8192. How I can sent more chars?

dim epoch
#

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' }));
arctic surge
#

server-side im using .js
client-side .ts

#
dim epoch
#

Yep.

#

Give a try
And let us know.

arctic surge
#

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)

dim epoch
#

I've update the snippet, try now.

arctic surge
#

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

dim epoch
#

Yep, sorry
Let me run it once on my function.

arctic surge
#

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

dim epoch
#

Okay

#

We also need to use js-base64
I'll update it the snippet

arctic surge
#

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);
dim epoch
#

Using this shrinked a 20K characters to just 4K nad was able to go the function

#

Can you share the payload data?

arctic surge
#

of corse

dim epoch
#

In network tab

arctic surge
dim epoch
#

Mmm, this one is 20K long
Meaning is more then the 8192 chars limit.

arctic surge
#

yes chatgpt says 10K ๐Ÿ™‚

dim epoch
#

With this amount of data you'll need to choose a different approach

#

Or

arctic surge
#

Okay, I feared that ๐Ÿ™‚
I tried to find a solution without storage.

dim epoch
# dim epoch Or

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.

arctic surge
#

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

dim epoch
#

๐Ÿ‘

arctic surge
#

But why is there a limitation from appwrrite. Do you know it?

dim epoch
#

Probably against abuse

arctic surge
#

hmm, okay. but for self host there should be a option to change the limitations. but its okay. We can find something

dim epoch
#

You are on self host?

arctic surge
#

yes

#

im not using the cloud

dim epoch
#

Change it to let's say 100000
You can still use the zip choice to get shorter upload times.

arctic surge
#

nice, I will try that definitly. Big thanks. That would help. I will keep you up-to-date

arctic surge
#

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?

dim epoch
#

What error do you get?