Include list of images from CSV as media filenames in form

Ok, so it looks like it's coming from the xlsform.org page via that forum post, it's not totally out of date (it includes the ODK xlsxform template from 2023), but it's not exactly current and complete.

Just for fun (because I don't use search() appearance and this way of referencing CSVs), I downloaded the example form & CSV from xlsform.org and added a column as described to the csv (myimage with a.jpg, b.jpg, c.jpg). Knowing that Central wouldn't ask for these files, I added a choice list fakelist that had one choice with a.jpg under image and called that list with a non relevant select in the form.

In your choices worksheet row, you may also include a .csv column name in the image column. If you do, the image filename to use will be pulled from the specified .csv column.

Outcome - much the same as you found, with a Webforms bonus;

  • Central called for

    • column name myimage as an attachment, type image (I added an image against it just to see... :dog_face: :fire: )
    • a.jpg type image (:mango: uploaded)
    • fruits.csv type Data File (uploaded)
  • In Enketo the form loaded with an autocomplete dropdown type appearance which could never display an image, but the selections for the question were ... and name, not the CSV content (the documentation does state it won't work)

  • In Webforms only name is an option, and the csv column name image appears!

  • In Collect the form loaded with a basic select appearance (single column) and a.jpg did appear and the others showed the File PATH is missing message. The CSV column name image doesn't show anywhere.

    • I added a second select removing the search appearance to see if anything would change, but it won't validate;

The XLSForm could not be converted: Question 'fruit' uses 'search()', and its select type references the choice list name 'fruits'. This choice list name is referenced by at least one other question that is not using 'search()', which will not work: 'fruit2'. Either 1) use 'search()' for all questions using this choice list name, or 2) use a different choice list name for the question using 'search()'.

So, my take on that part of the documentation is: It was written pre Central where you could upload whatever you like, so if you used Collect and not Enketo/Webforms, and did correctly upload all the filenames to Aggregate (or manually transfer the files to the device definition media folder), it 'works' (for some values of work). The search() approach is only for Collect, and only if you have an absolutely massive dataset that won't be performant via select_one_from_file.

And @seewhy for your case, the only current way to get it to work is to include the filenames in your xlsxform as well as the CSV, and if you don't want to modify the form, you'll have to include a onetime list like 0001.jpg 0002.jpg ... 9999.jpg and assign those to rows in your CSV - but you'll still have to update the definition in Central in order to modify the attachments so this isn't much better... :person_shrugging: You might also want to :-1: the kapa response to downvote it to oblivion for future queries.

BTW When I mentioned entity media earlier, this describes me perfectly, and I think would also solve your issue :smiley: :

2 Likes