Once again I’m coming late to the party, but glad of the Forums here for capturing these questions for new generations of Anvil users (=me!).
So I’ve followed these docs on Media and Files, and the link to the Uploader component…
My initial code worked fine for a 20MB data file:
Client
def upload_address_lines(self, file, **event_args):
"""This method is called when a new file is loaded into this FileLoader"""
file = self.file_loader_1.file
file = anvil.server.call('_store_uploaded_media', file, "Address_Data_UK")
self.file_loader_1.clear()
Server
@anvil.server.callable("_store_uploaded_media")
def _store_uploaded_media(media, custom_name):
media_upload = app_tables.uploads.add_row(name=custom_name, media = media, datetime = datetime.datetime.now()) # <<< This is "Line 38"; see error message below
print(f"{media.name} saved to 'uploads' database as {custom_name}.")
return media_upload
But presumably because of some timeout designed for reglar code execution, I get the following error consistently with a larger (40MB) data file even with my fast broadband connection which I use daily for video editing and transfers of several GB at a time:
anvil.server.TimeoutError: Server code took too long at [HomePage._DeveloperTools, line 38](javascript:void(0))
Is there a way of deactivating or lengthening the timeout for such an upload please? The only workaround I’ve found so far isn’t very satisfactory because I have to manually open up the Datatable for client writes and this obviously exposes the Uploader to potential abuse, even if temporarily:
def upload_address_lines_client_only(self, file, **event_args):
"""This method is called when a new file is loaded into this FileLoader"""
file = self.file_loader_1.file
media_upload = app_tables.uploads.add_row(name=file.name, media = file, datetime = datetime.datetime.now())
print(f"{file.name} saved to 'uploads' database.")
self.file_loader_1.clear()
Alternatively, is there any way I can programmatically permit, then immediately restrict, Datatable writes from the client e.g. based on user rights I specify?
All the best,
Peter