I have a client server running using the Anvil Uplink. When I call a function from that server, a very large amount of data is supposed to get returned to anvil, however, when the data is passed back, the uplink disconnects and resets itself, and I never get the data back in my anvil app.
I get this error printed in the console: Anvil websocket closed (code 1006, reason=Going away)
The data is in JSON and the size of the data is 109KB. I don’t know how to give you a sample of the data without pasting it here, which would take up a lot of space. I can’t give you access to the api call, as it is an internal company api.
The disconnect happens almost instantly when I try to return the data over the uplink. What is happening is that I make the api from a local server and try to return the data to anvil over the uplink. As soon as I try to return it, the error fires.
I ran this function to get the size of the response: size = sum(len(chunk) for chunk in response.iter_content(8196)), which returned a size of 4515177.
How do you measure that file size? Are you returning it as dicts and lists from the uplink function, or as a string, or in a Media object?
Serialised data returned from uplink or server modules currently has a size limit of 4MB, excluding media (so, if you want to send more than 4MB of data, try sending as Media) - but it looks like your payload is well below that size, so something funny is going on…
Can you share the data you’re sending as an email attachment to support@anvil.works?
Further investigation revealed that the data was actually 4.9 MB rather than 109 KB, which explains why the transfer was failing. Until we have support for sending larger Python objects, the workaround is to send as a Media object:
So now it seems you need to have on the server: return anvil.BlobMedia("application/json", json.dumps(data).encode())
And at the other end: data = json.loads(returned_media.get_bytes().decode('utf-8'))
Quite right! The change here was that the default Python version switched from Python 2 to Python 3, which distinguishes between bytes and strings. Your sample code is (at the time of writing) correct!