I have tried to insert a dictionary of media object that look like this into {‘img_1’: <anvil.FileMedia object>, ‘img_2’: <anvil.FileMedia object>} a Simple Object Column and got the following error:
anvil.tables.TableError: You can only store strings, numbers, dates, references to other table rows, or simple objects in a table
Here are my codes:
anvil.server.call(‘upload_file’, self.description.text,float(self.price.text),files)
self.file_loader_1.enabled = False
self.progress_lbl.text = “Uploading…”
n_files = len(self.file_loader_1.files)
n = 0
files={}
for file in self.file_loader_1.files:
n += 1
self.progress_lbl.text = f"Uploaded {n} of {n_files} files"
files[f"img_{n}"]=file
can hold only “Python strings, numbers (not NaN), or dicts or lists” of these types. Notice that “Media Object” is not one of these types. A Media Object can only be stored in a column of type Media, and then only one per row in that column.
If you really need to store multiple Media Objects in a place where just one Media Object fits, there is a way: Zip up your Media Objects, as if they were named files, into a Zipfile; then store the Zipfile as a single Media Object. You’ll need Uplink or Server-side code to Zip and Unzip the Zipfile into its component Media Objects.
Otherwise, you might make a separate table for your Media Objects, one per row, with enough additional data (columns) per row to properly identify each Media Object.
This is what I do with my main app, and then I store the unique identifier (a string) into Simple Object columns along with other data. It works very well.