Exception: The 'file' property for a FileLoader is read-only

Is there a way to supply the uploader a existing file from the db or not? The use case here is I have a update snake page that when you select a snake from the dropdown I pull all the data from the db and then update the form with the information so it can be modified.

This works fine for everything except the image object because of the error above I was just trying to set my uploader file to include the file I already have but I guess my only option is to just let them upload a new file and if there is one there then we modify the existing one in the db or is there a better way to do this?

self.snake_image.file = snake_record['snake_pic'] where snake_record[‘snake_pic’] is a image object in my db this is where this error is obviously coming from. Wasn’t sure if maybe I should just load the image there next to the uploader and give a new upload option, etc still trying decide the best approach.

Thanks

Images can have their source property set to a Media object. So if you have a file stored as a Media object in a Data Table, you can retrieve it and assign it to the source property of your image.

For example, if I have a table named ‘files’ with a column named ‘contents’ that contains Media objects, I can do

self.image_1.source = app_tables.files.search()[0]['contents']

ok so I tried that and I’m not getting any error but I don’t see the file show up in the uploader:

But you can see from printing my image object its there:

<anvil.LazyMedia object>

self.snake_image.source = snake_record['snake_pic']
print(self.snake_image.source)

In this case snake_record[‘snake_pic’] is my media object in this table.

Thanks

I guess I would have to maybe build it like this and just have the image update if they click upload then update snake

You should be able to trigger the image source change from the FileLoader’s change event, is this not working for you?

I’ll try it out again and see