We want to rename some config fields in kots config
To preserve current values of future-deleted field during updates, we kept the old fields, making them hidden
We use value field to set the old value inside new fields
I’m trying to configure a type file using value to set the file and filename from the old field
I’m not even sure I can set the filename using value in a Config object (like in ConfigValues )
I’m struggling a bit on it, would you have an example for that ? Or another method to accomplish this ?
Hi @Gautier, I’ve been testing some things out to see what you might be able to do here.
In the documentation for file config items, it’s mentioned:
Only the contents of the file, not the name, are captured.
That being said, it does seem like you could take a similar approach for these config items as you are for the others. You can leverage the ConfigOptionData template function to set the value for the new config item based on the old value. The value would need to be set to the base64 encoded file. Something like this should work:
- name: some_file
title: Some File
type: file
hidden: true
- name: some_new_file
title: Some New File
type: file
value: repl{{ ConfigOptionData "some_file" | b64enc }}
This would at least get the file contents transferred over to the new field, though you would lose the name because of that limitation.
Does this sound like it would help for your use-case?
Side question, why do you use ConfigOptionData instead of ConfigOption that would give the base64 encoded string directly?
Good call, I’m used to using ConfigOptionData with these file types, so it was simply out of habit. You can definitely just use ConfigOption here since you actually do want the base64 encoded value. So the updated snippet would be:
value: repl{{ ConfigOption "some_file" }}
Let us know how it goes when you get a chance to test it out.
Thanks for raising that issue with the download, as I’m seeing it on my end as well. I’ll investigate this today as that does feel like a bug. Thinking through it a bit, since we do have the file name limitation, we would likely not be able to provide an accurate name for the downloaded file, but still should be able to provide something as we do still have the data.
@Gautier I stumbled upon something when digging through the related KOTS code. It seems that you could also set the filename field on the config item using the ConfigOptionFilename template function it would allow you to preserve both the name and value. For example:
- name: some_file
title: Some File
type: file
hidden: true
- name: some_new_file
title: Some New File
type: file
filename: repl{{ ConfigOptionFilename "some_file" }}
value: repl{{ ConfigOption "some_file" }}
Doing this also allowed me to download the file too as it appears the download issue was related to the missing name. Are you able to try this out on your side?