Accessing form attachment in code

I'm trying to access an uploaded bizform file that was uploaded using the FileUploaderComponent upon form submission. The API documentation I linked below is less than helpful.

I can get the form submission column data but I'm unable to retrieve the submitted file. My simplified code is shown below:

var path = "/assets/bizformfiles/" + file.SystemFileName;
var fileBytes = CMS.IO.File.ReadAllBytes(path);
var ms = new MemoryStream(fileBytes)
{
    Position = 0
};
emailMessage.Attachments.Add(new(ms, file.OriginalFileName));

Environment

Tags:
Form Builder SaaS v31.5.0 ASP.NET Core

Answers

Accepted answer

I haven't tried this myself, but there are two types used to manage files of Form Builder file component uploads.

  • CMS.OnlineForms.IBizFormFilePathProvider - Provides physical folder paths for BizForm files and temporary files.

  • CMS.OnlineForms.IBizFormFileService - Defines manipulation methods for a file uploaded via forms.

You want IBizFormFilePathProvider to get the non-temp path files are stored in. Then you can use your File.ReadAllBytes() approach or CMS.IO.StorageHelper.GetFile(path) if you need more metadata.

The BizFormFilePathProvider keeps the files path abstracted away in case you use custom storage path mapping to move things around or use cloud storage.

Thanks Sean.

Unfortunately, the APIs you mentioned weren't introduced until 31.6.0, so we had to apply the latest hotfix, and then we could test out with the APIs you mentioned. After that hotfix update, the CMS.OnlineForms.IBizFormFilePathProvider was a great help in finding the proper path to stream the file as an attachment. Thanks for the suggestion.

To response this discussion, you have to login first.