End user docx file upload with FileLoader

As part of my application, i want to enable a pretty straightforward scenario as follows:

  1. user uses fileloader (the upload widget in design mode) to choose/select a Microsoft Word document (.docx) file for uploading :

def file_loader_1_change(self, file, **event_args):
“”“This method is called when a new file is loaded into this FileLoader”""
file_to_analyze = file

  1. uploaded file is sent to server side code :

anvil.server.call(‘my_server_function’, file_to_analyze)

  1. on Anvil server side get the file and send the file via uplink to an external (external from Anvil that is) computer:

@anvil.server.callable
def my_server_function(file_to_analyze):
anvil.server.call(“my_remote_computer_uplinked_function”, file_to_analyze)

  1. open the Word file on remote computer, process it, save the results of processing, and return the processed file back to Anvil server app for further disposition

The problem is i get the following error when i try to open the file on the remote computer:

AttributeError: .Open
at C:/users/james/appdata/local/programs/python/python38/lib/site-packages/win32com/client/dynamic.py, line 554
called from C:/Users/James/AppData/Local/Temp/ipykernel_10368/3064749683.py, line 346
called from C:/Users/James/AppData/Local/Temp/ipykernel_10368/3064749683.py, line 2697
called from ServerModule1, line 18
called from Home, line 80

The application works fine on the non-Anvil remote computer when i load the Word docx into the remote application using a local Word file on disk.

But when i try to pass the Anvil uploaded file it does not recognize the file type when i try to open it.

I have been assuming that the actual Word docx file itself that was uploaded on the Anvil platform is what I am passing over via uplink to my application so I just cannot fathom why it is not working.

Any ideas on what to do??.

What you get from the file uploader is a Media object. Did you download that on your remote computer? Anvil Docs | Files, Media and Binary Data

Downloading the Media object using the code shown in the docs gets you the original Word file on your remote computer’s hard disk.

Thank you jshaffstall. I will go back to the docs and look at the code there again. I must have missed something…

So, this function, or one it calls, is experiencing the error you describe. You’ve said what you intend that function to accomplish. But we aren’t seeing this function’s code, so we can’t tell what it’s actually trying to do.

For proper formatting, please put a line consisting of ``` (that’s 3 backticks, not 3 apostrophes) before and after each code block. This will preserve the indentation that is crucial to the meaning of the code.