Attachment - File Type/Extension
Tuesday, September 12, 2023 at 03:51pmFor attachments that are uploaded, how can I get the file extension (PDF, jpg, tif, etc...)? I only see these attributes on OneSpanAPIOjbects.AttachmentRequirement:
this.data = data;
this.description = description;
this.id = id;
this.name = name;
this.required = required;
this.comment = comment;
this.status = status;
I am saving the document to a ContentVersion and we have been setting:
ContentVersion.PathOnClient = documentName + '.pdf'
I need to make this dynamic with attachments.
Reply to: Attachment - File Type/Extension
Wednesday, September 13, 2023 at 11:23amHi Peter,
You can extend the API object in below way:
public class AttachmentRequirement
{
public string name {get;set;}
public string description {get;set;}
public string status {get;set;}
public string id {get;set;}
public string comment {get;set;}
public boolean required {get;set;}
public List<AttachmentFile> files {get;set;}
......
}
public class AttachmentFile
{
public Long id {get;set;}
public Long insertDate {get;set;}
public string name {get;set;}
public Boolean preview {get;set;}
}
In real practice, if the file.size() > 1, the downloaded file is a zip file. There's a package/account level setting "maxAttachmentFiles" where you can force signers to upload a single file per attachment requirement:
"settings": {
"ceremony": {
"maxAttachmentFiles": 1
}
}
And if the AttachmentRequirement.status == 'COMPLETE' && file.size() == 1, you can retrieve the uploaded file's extension by:
attFile.name.substring(attFile.name.lastIndexOf('.'))
On top of that, you can also limit the allowed uploaded file type, it's documented in this dev blog:
https://www.onespan.com/blog/onespan-sign-developers-signer-attachments-management
Duo