Update attachement filename

Hi all,

I’ve configured personalised path and filename like this for my attachments :

If the field “Nom” changes, the name does not seem to update. How to?

Or should I use uuid instead?

I think you’ll be better up using some unchangeable value like an uuid, or even the fidyour layer most likely already has; something unique just to relate the photos with the feature. Otherwise, there seems to be no trivial way to resolve what happens when you change the other attribute, for example:

  • previous photos should be moved to the new path?
  • what if the photo is missing or just temporarily unavailable (on a remote drive for example)?
  • what happens if there already is a file with that name?

I think qgis in general pretty much avoids handling the attachments for you. For example, if you delete a feature on QField, or even if you take a new picture, the old picture stays on the drive. So think of the attachments as something you have to handle “manually” on your end. Giving the path an unchanging and predictable name is an easy way to handle them, although it does not look pretty.

Tangentially, I see that you are storing more than one picture. If this is only to give the user the possibility of taking multiple photos per feature and there is no specific meaning for photo1 and photo2, maybe you can create an additional table that holds multiple pictures per feature. QField will then show you all the related pictures in a gallery when you open the feature form, and you can dynamically add as many as you want (it can even be a picture plus an optional description or any number of additional attributes per picture). Check this video tutorial to see an example of how this can be done.

  1. Try to use concat() instead of ||.
    I succeed with more complex expressions with that.
  2. Another subtle tweak to try : if not already in your form, add “Nom” field in it, hide it if not needed and call it with current_value("Nom") : instead of taking the value from the table, it takes the value from the form…

Hi all,

@cuprico thanks for the explanation, I’ll stick with my two fields for this specific project but it’s good to know!
@VxTedxV I’ve changed from || to concat() plus current_value("Nom") and got no return from current_value("Nom") in the picture filename (all the rest of the filename is correctly concatenated.

I’ve finally opted for uuid('WithoutBraces') in the attachments settings.