File Upload in Sitecore 9.3 Forms

With Sitecore 9.3 forms, the file-upload component has finally been added to the platform. Lets have a deeper look at the capabilities of this component.

SQL file storage provider

When a file gets uploaded through your form the Sitecore.ExperienceForms.Mvc.Pipelines.ExecuteSubmit.StoreFiles processor from the Forms.executeSubmit pipeline gets executed. This pipeline will make a call to the IFileStorageProvider implementation of your solution. By default this is the SqlFilestorageProvider which will store the file in a new table of the Sitecore Forms database. You can also opt to store the files in a different database by defining an extra connectionstring and referencing it in Sitecore.ExperienceForms.config.

In the database, the original filename gets stored along with the created date, the filecontent, an id (guid) and a committed flag.

Custom storage provider

If you want to store your files in a different location, like Azure Blob Storage, you can create your own custom storage provider. Detailed info on creating your provider can be found in the official Sitecore documentation.

The IFileStorageProvider interface has 5 methods to implement:

  • Guid StoreFile(Stream file, string fileName) In this method you will have to store the filestream somewhere and return a guid to retrieve the file upon request.
  • StoredFile GetFile(Guid fileId) Retrieve the file back from the storage using the guid you provided in the StoreFile method.
  • void DeleteFiles(IEnumerable<Guid> fileIds) Delete the files in the guid list from the storage.
  • void CommitFiles(IEnumerable<Guid> fileIds) Mark the files from the guid list as Committed in the storage.
  • void Cleanup(TimeSpan timespan) Delete the uncommited files in a given timespan from the storage.

With Sitecore Forms Extensions 3.x, a storage provider for Azure Blob Storage will be provided out of the box.

Retrieve the uploads

When a form gets stored in the database, the upload field will contain the GUID as its value.

That’s off course just raw data. Luckily when exporting your form entries using Sitecore Forms’ export functionality, you will get a URL to the file for download.

These URL’s are secured and require you to authenticate into Sitecore. The download is embedded into the system and agnostic of the FileStorageProvider you have chosen to use.

Conclusion

The new file upload is well thought through and offers the ability to add your own storage location. (Out of the box, you limitted to the SQLFileStorageProvider)

Currently missing is the ability to add uploads as an attachment in your EXM emails.

With Sitecore Forms Extensions 3.x (soon available), you will be able to add the uploads as an attachment in your emails and also have the ability to use Azure Blob Storage.

Leave a Reply