What I’m trying to do:
I made an app that lets a user upload a file and type a name for the file, in which it’s stored in an anvil datatable with columns “name” and “file”. They can also download any previously stored file from a dropdown menu that’s populated by the “name” column values, and everything works nicely.
However, I would like to make the app nicer by throwing an alert or popup message that tells the user the file successfully uploaded and to clear the text input upon insert success. Is there some sort of event handler for datatable transactions so that I can call it and trigger a message of some sort? I tried searching various ways to say “event handler for datatable” but I couldn’t find a relevant thread.
If I’m understanding correctly, you could have the ‘add_file’ server function return whether the upload was successful. Then put the alert (and text-clearing code) right after your anvil.server.call('add_file'... line in the ‘else’ clause of your ‘upload_click’ method.
Ah so there IS a way haha! Is there a specific part of the documentation you can lead me towards for how to tell if an upload is successful? I have the implementation design all worked out so far, but I don’t know what built-in functions/methods to call to confirm that the upload was successful so that I could throw the popup alert.
Perhaps I’m wrong, but I believe that upload occurs entirely on the Client, resulting in a Media Object in the FileLoader object’s file member (or files if you’re uploading multiple files) on the Client. Transmitting that to the Server is a separate step.
If the upload process fails, I believe it should raise a Python exception, in the Client. However, I have found no documentation saying so. Nor can I see which type of Exception that should be caught. (You may want to experiment with deliberately failing/cancelling an Upload to see what happens.)
In the meantime, I’ll add this omission (?) to the ongoing Documentation discussion.
Thanks for adding it. I usually try to find the answers on my own as much as possible before I make posts and just couldn’t find any documentation or forum post pertaining to it.