Skip to main content
June 28, 2022
Solved

Remove file immediately, if extension is not "PDF"

  • June 28, 2022
  • 10 replies
  • 0 views

HI All,

I am using a!fileUploadField for uploads file, which has validated to allow only "PDF" file, 

Our ask is, if uploaded file extension is not PDF, shall remove immediately, how i can do that?

Note:- file upload feature i have given on a grid column and it's single select.

Best answer by harshitb6843

Use the below code then. 

a!fileUploadField(
                label: "File Upload",
                labelPosition: "ABOVE",
                value: ri!document_doc,
                saveInto: {
                  ri!document_doc,
                  a!save(
                    ri!document_doc,
                    if(
                      rule!TA_checkFileExtension(document_doc: ri!document_doc)="PDF",
                      null,
                      ri!document_doc
                    )
                  )
                },
                target: cons!DA_DESIGNER_DOCUMENTS,
              )


TA_checkFileExtension

tostring(
  a!fileUploadField(value: ri!document_doc).contents.value.extension
)

10 replies

stewart.burchell
June 28, 2022

What's the use case for the "immediate removal"? If you implement validations that check for PDF only files, then the User cannot progress with the process which is the actual objective here. Is it just an optimisation you're looking for to save the User from removing the current file before uploading a new one?

June 28, 2022

if user tried to upload wrong file (not pdf), instead of showing error message along with file, remove file from field and make it file upload field empty before save

stewart.burchell
June 28, 2022

The problem here is that there will be no indication to the User what the issue is as the file will have been removed which means the validation logic won't trigger and the User won't seen an error message. The UX at this point is that their file has disappeared with no indication why and they'll think there's a bug in the system and won't trust it. 

I'm not sure that's a good pattern to be aiming for.

Systems that Users interact with should follow good "Dialogue" practices. The User asks the system to do something, the system replies accordingly. What you're asking for breaks this good practice.