How to add a file to Data Files using code?

What I’ve tried and what’s not working:
I have look over and over for a way to add my CSV file to anvils Data Files using code and a File Loader but it seem to only be possible to upload the CSV file manually right into anvil.
(It seems impossible so this thread might have to be moved to feature request.)

Code Sample:
Main Code:

def file_loader_1_change(self, file, **event_args):
  self.file = self.file_loader_1.file 
  anvil.server.call('importCSVdata',self.file)

Server Code:

@anvil.server.callable
def importCSVdata(file):
  with open(file, "r") as f:
    df = pd.read_csv(f)
    for d in df.to_dict(orient="records"):
      # d is now a dict of {columnname -> value} for this row 
      # We use Python's **kwargs syntax to pass the whole dict as 
      # keyword arguments 
      app_tables.devtesting.add_row(**d)

The above code is what I have tried but that is just not how it works. I already know that the place where I try to open the file in read mode is supposed to be the file location or directory and not the file itself.

with open(data_files['colours.csv'], "r") as f:

If anyone knows of an alternate way of doing this please leave it in the comments ASAP.

Hi, did you manage to find a solution? I would also like to use the fileloader to update some permanent excel tables

This might be a good starting point: Data Files storage.