Upload file with RecordEditForm

Hi There,

I am trying to give the user the option to upload their SSL certificates in the ignition module. I am using RecordEditForm.

in my PersistentRecord, I have fields:

 public static final StringField KeystorePath = new StringField(META, "keystorePath", SFieldFlags.SMANDATORY)
            .setDefault("");
    public static final StringField TruststorePath = new StringField(META, "truststorePath", SFieldFlags.SMANDATORY)
            .setDefault("");

and

static {
KeystorePath.getFormMeta().setEditorSource(FileUploadEditorSource.getSharedInstance());
TruststorePath.getFormMeta().setEditorSource(FileUploadEditorSource.getSharedInstance());
}

it gives me the upload form inputs on the configuration page, but after saving, nothing is saved. perhaps needs to write the upload functionality. but how can I get access to the file when saving it? is there any example of how to do it?

You are blazing a new trail. It will all be moot, and need to be redone from scratch, in v8.3. How urgent is this?

Thank @pturmel for the quick response.
I didn't get the opening new trail part. but I didn't find any discussion in the forum regarding this. LLMs are not that helpful, just causing confusion.

I wish I could see an example of this. so that would be easier to fathom.

my wish is simply to give the upload file option and be able to upload them somewhere in the ignition, get the path, and then be able to retrieve them when used.

Sorry, english euphemism for "being the first to do something".

Which is why you haven't found examples, nor is any LLM going to be helpful. (They are generally not, with Ignition, and there's a warning in the FAQ about sharing their output here.)

Yeah, sure, this code is not generated by LLMs.

about the being first to do this, code-wise, I'm not sure, but approach-wise, have seen other modules(MQTT for example):

do you know how this has been done? is there a reference or a thread to pull? :slight_smile:

Cirrus Link modules are commercial, closed source. (Like mine, fwiw.) So, no, not any public information on how they did it. Perhaps you should ask (nicely) on their forum?

2 Likes

The SECS/GEM module does this with the following:
0. The stuff you're already doing in the form meta.

  1. Subclassing RecordEditForm
  2. Setting up a private final field to hold the FileUploadField:
    private FileUploadField uploadField;
  3. Overriding newEditorComponent to capture the value in the field:
    @Override
    protected Component newEditorComponent(String id, FormMeta formMeta, RecordEditMode mode, SRecordInstance record) {
        Component comp = super.newEditorComponent(id, formMeta, mode, record);
        if (formMeta.getField().equals(EquipmentRecord.SecsDefinitionFile)) {
            uploadField = (FileUploadField) ((AbstractFormComponentEditor<?>) comp).getFormComponent();
        }
  1. Overriding onSubmit and extracting the list of uploaded files:
List<FileUpload> fuList = uploadField.getModelObject();

The same general approach should work, though I'll echo Phil's general sentiment that the less engineering effort spent on wrangling Wicket the better.

3 Likes

@PGriffith You're an absolute hero. that helped very much with a little bit of tinkering around!

1 Like