Data Payload too big for media URL?

Hi There,

I have several Apps that suddenly throw this error:

In the case of the screenshot above the following line server side causes the error:
return anvil.users.get_user()['media_puffer'].get_url(False)

Can the URL actually be larger than the payload limit?
Or could there be something else the case here?

Cheers,
Mark

Hi Mark,

It is certainly possible for the URL to be too big, if the Media object is large and what it’s returning is a Data URL. Please can you try replacing

return anvil.users.get_user()['media_puffer'].get_url(False)

with

url = anvil.users.get_user()['media_puffer'].get_url(False)
print(len(url))
print(url[:30])
return url

and posting the results?

Thanks!

Hi @daviesian,

thanks for your Help!

I just tried that but it seems the code is not executed that far. The debugging link in the output menu points to the client side function that calls the server side function which creates a PDF and sends back the URL. (There is no other return path except this one - that does not seem to be executed)

Also this error occurs all over my apps, could it be that I’ve reached a Limit of the individual plan?

Cheers Mark

Hi Mark,

No, none of the usage limits affect this, so that’s not the problem here.

It seems there is some confusion over where the error is coming from. I’d like to take a closer look to work out what’s going on! Are you able to reproduce this problem in a new, small app that you could share a clone link for?

Hi @daviesian,

thats strange then…

i clouldnt reproduce it so far and unfortunately I cant share the app on which it occurs.
I will try to reproduce it once i get some time.

One more thing, i recently changed all my app dependencys on development. Could be just a coincidence but the errory started after that…

best, mark

Hi @mark.breuss,

To clarify: This problem occurs when you try to return too much data from a server function as strings/dicts/lists/etc. If you return Media objects, they don’t count against this limit.

It looks like what you’re doing is trying to get a URL from a Media object, and return that, rather than returning the Media object from the server function and then getting its URL on the client, and that get_url(False) is doing something different on the server (in this case, trying to get a huge data: URI!)

What happens if you just return the Media object from the server, and call get_url() on it on the client?

1 Like

Hi @meredydd
thanks for your answer!

I tried to change the get_url() statement, however it still breaks. Therfore I did some further investigation.

To me, it seems like the code breaks when creating the PDF file. Which makes the error message even stranger since i thought that rendering PDFs happens soley on the server?

Function that creates Multiple PDF Orders: (as discussed in Problems Creating Multiple Anvil PDF's )

#... the variable data (list of orders is created) -> could get quite large
  
  
  print('point3')
  
  #2. Generate pdf based on the data
  pdf = PDFRenderer(page_size='A4',filename=str(row['id']) + '.pdf',quality='original',
                    margins={'top': 0.3, 'bottom': 1.5, 'left': 1.5, 'right': 1.0}
                   ).render_form('MarkOne_Bestellungen.mulitple_a5_orders',data)
  
  print('point4')
  #3. Store the pdf temporary on the user db
  anvil.users.get_user()['media_puffer'] = pdf
  print('point5')
  #4. Return the urls so it can be printed with the js fuction
  url = anvil.users.get_user()['media_puffer'].get_url()
  print(len(url))
  print(url[:30])
  
  print(datetime.now()-start,'1') #how fast was it?
  print('point6')
  return url

Output

@meredydd unfortunatelly the error still occurs.

Although I could proboably build a workaround i think the fact that the error occurs when creating a PDF is very strange?
Thus I guess it might be something you guys are interested to know.

cheers, Mark