Enable custom file naming convention for images

It would be great to enable custom file naming convention for images / media files. Ideally this could be defined inside the XLSForm. This would enable adding custom elements to the file name, e.g. date, values from other fields, form ID, user name etc.

It looks like file naming is currently using System.currentTimeMillis() function to create file names: https://github.com/getodk/collect/blob/137dbe1099d12c57e96c4266226c5eabd05a7848/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java#L873. More meaningful image names would be very helpful in many use cases.

Hi @janekb,

Linking this features request with the post discussed previously (for documentation):

@Xiphware any thoughts with this request?

I would probably have to first ask what the specific requirement is that (internal) server-side filenames need to be specified by the user? eg is there a particular reason why a “IMGXXXX.jpg” naming convention is required?

There are actually good reasons why it’s generally not a good idea to have the client dictate what name a file is actually stored internally as on the server; eg what if, as an API client app, I state "store this file as ‘…/…/etc/passwd’. Nor is doing so a particularly scalable one - think about uploading images for the same form from different devices that may well have current overlapping “IMGXXXX.jpg” namespaces.

1 Like

Hi @Xiphware,

Thanks for following up. I can think of multiple reasons why this would be useful to customize file names (images), e.g.:

  • custom names would allow working with images directly in the file system, without referring to survey data (e.g. sorting or filtering by name, which may include project name, category, surveyor’s name etc)
  • external requirements (e.g. imposed by clients on how images should be named or by external apps / systems - e.g. file names should not start with a digit, or there might be a file name length limit)
  • aligning with naming conventions used by other systems / applications

what if, as an API client app, I state "store this file as ‘…/…/etc/passwd’.

Not sure what you mean here? Do you mean that client would customize a path for storing the image? I think only file name itself could be customizable. Special characters (such as “/” etc) could not be permitted (to ensure safe file names).

think about uploading images for the same form from different devices that may well have current overlapping “IMGXXXX.jpg” namespaces.

Is there any limitation from ODK/KoBo side if file names are duplicated? Also, even using System.currentTimeMillis() does not ensure global uniqueness.
As far as I can see, when downloading media attachments, they are stored in separate folders for each form/project and each submission. So custom file names should be unique for each submission (two file names in the same folder are not allowed). - I’m sure this could be easily worked around, the same way as Windows is copying/pasting files with the same name (e.g. adding "_Copy1" etc…

I would like to give an example, why I think it might be useful: We just made a little form for the team in the field to enter the bills with a photo. Now I have a nice little excel table with the items, the amount and a jpg file with a long number. I would love to have instead the date, the item and the amount directly on my jpg file (example: 2020-12-18_office_fotocopies_20USD.jpg) so that it is easy to go through the jpg files without the excel sheet. It would be great if this info is collated directly from the entries made into the kobo form.
Also if I sort other photos from people or plants, it would be good, if I could read already from the name of the jpg, what the picture is about. Nice to have, I think and it should be up to the user to decide if she/he likes it or prefers to stick to the number. Doesn’t seem to hurt the system?
Cheers, Bettina

The best way to manage the issue you mention would I think be via direct links and not custom file names. You can export your data in excel form and then use the image file names included to create either a column of hyperlinks or a column of links to local folders which allows you to directly view the relevant image.

It connects the image to your data in a much more reliable and scalable way and takes much less time than looking through lists of images labelled with various dates and item names etc. (some of which may have duplicate names). This system worked very well for me with forms collecting hundreds of images every day.