File upload command

This topic provides information nearly the file upload control. This control lets users upload files.

Overview

The file upload command lets users upload a file. Information technology also lets developers control the upload process and manage the file that is uploaded, based on their requirements.

Illustration of file upload control.

The file upload command can have three styles. You lot control the style past using the Style property.

  • The Standard style shows the file name field together with Scan, Upload, and Cancel buttons.
  • The Minimal style shows only the Browse push button.
  • The MinimalWithFileName mode shows the file name field and the Browse button.

The FileTypesAccepted belongings of the file upload control lets you limit the types of files that users tin upload. The file types that users can upload are primarily controlled past the associated upload strategy. The FileTypesAccepted property on the file upload control should be used only if further restrictions are required. If the upload command tries to specify file types that are restricted by the upload strategy, the Browse button becomes unavailable.

Allowed file types Immune file types from the upload strategy Last result
".jpg,.png" ".jpg,.png,.gif,.txt" ".jpg,.png"
"prototype/png" "image/*" "image/png"
"prototype/*" "image/png" The Browse button is unavailable.
".jpg,.png,.gif,.txt" ".jpg,.png" The Browse push button is unavailable.

You tin can use the OnBrowseButtonClicked, OnUploadAttemptStarted, and OnUploadCompleted overrides to hook into the various stages of the file upload process. You can also create custom file upload strategies and associate them with a file upload control by using the FileUpload Strategy Class property.

Design classes

In that location are two base classes that developers can work with for the file upload control:

  • Upload strategy class – This base form lets developers control various parameters that should be enforced for uploaded files, such as the types of files that a user tin can upload and the maximum size of a file. It likewise lets developers decide where and how the uploaded file should be stored. All derived classes used for upload strategies must inherit from the abstract FileUploadStrategyBase form.
  • Upload result course – This base form lets developers access the details of a file that was uploaded by a user, such as its name, content type, and upload condition. It also lets developers open and delete the corresponding file. All derived classes used for specializing upload results must inherit from the abstract FileUploadResultBase grade.

The framework provides a default upload strategy class that is named FileUploadTemporaryStorageStrategy and a default upload result class that is named FileUploadTemporaryStorageResult. This upload result class stores uploaded files to the temporary blob storage and provides a download URL. Developers can as well implement their own custom upload strategy and upload outcome classes as required. For the upload strategy, 2 abstract methods from the FileUploadStrategyBase grade must exist implemented: uploadFile and getResultClassName. The uploadFile method handles where and how the file is stored. The getResultClassName method retrieves the upload outcome class that is used in this strategy. The FileUploadResultBase class has fields for the file name, the upload condition, the content type of the file, and the log message. This class tin can be extended every bit required. All new backdrop should be able to be serialized and deserialized. The openResult method opens the file as a stream, and the deleteResult method deletes the file from the corresponding data storage.

Sequence diagram

The file upload control accepts the file and upload strategy in the customer, and sends them to the file services. The file services starting time a new session, create an instance of a strategy form, and telephone call the uploadFile method. When the uploadFile method has finished storing the file in the data source, a file upload result course returns to the file services. This form is sent dorsum to the client, which might trigger the OnUploadCompleted event to deal with the post-process.

File upload sequence diagram.

Scanning uploaded files for viruses and malicious code

Before you upload a file into the system, you might want to browse it for viruses or malicious code. Therefore, in version 10.0.12 and later, an extension point is available so that customers can integrate the file scanning software of their choice into the file upload process. Similar extension points are also bachelor for scanning attachments. For more data nigh those extension points, encounter Configure document management.

Important

Out of the box, Finance and Operations apps don't scan files for viruses and malicious lawmaking, and we don't recommend specific software for file scanning. Instead, customers are responsible for choosing their own file scanning software, and for adding the appropriate code to the delegate handlers then that they can employ the software or service of their choice to scan files.

In detail, the FileUploadResultBase class exposes the delegateScanStream() consul. This delegate applies to whatsoever file upload scenario where the Upload strategy class has been specialized. The upload process will neglect if the scanning service determines that the file is malicious.

Implementation details

The following example of the ScanDocuments grade shows boilerplate code for the handler. For full general information most how to implement handlers for delegates, see EventHandlerResult classes in asking or response scenarios.

                              public final class ScanDocuments     {          [SubscribesTo(classStr(FileUploadResultBase), staticDelegateStr(FileUploadResultBase, delegateScanStream))]         public static void FileUploadResultBase_delegateScanStream(System.IO.Stream _stream, EventHandlerRejectResult _validationResult)         {             if (!ScanDocuments::scanStream(_stream))             {                 _validationResult.reject();                        }         }          individual static boolean scanStream(Arrangement.IO.Stream _stream)         {             /*              Custom implementation required for connecting to a scanning service             If document scanning procedure found an effect, return faux; otherwise, return true;             */             return true;         }     }