Handle multiple file uploads and file drop zones

Completed

Developers can handle multiple file uploads and designate different page parts as file drop zones.

This empowers AL developers to create more flexible and user-friendly interfaces within Business Central. Designating specific page parts as file drop zones lets people upload multiple files at the same time, which improves efficiency.

This feature is valuable for developers working on applications or customizations that require users to upload multiple files simultaneously. By allowing users to drag and drop files onto designated page parts, developers can streamline the file upload process and simplify data entry.

The following example designates a group and field as file drop zones by referencing the ProductImageUpload action in the FileUploadAction property. The FileUploadAction action's AllowMultipleFiles property lets developers specify whether an action can handle a single file, or multiple files. The AllowedFileExtensions property allows developers to specify the file types that people can drag to a drop zone. After you drag one or more files to a group or field on a HappyDragAndDrop page, the OnAction trigger in the FileUploadAction property is called with the list of files.


page 50102 HappyDragAnddropPage
{
    PageType = Card;
    SourceTable = item;
    UsageCategory = Administration;

    layout
    {
        area(Content)
        {
            group(GroupName)
            {
                FileUploadAction = ProductImageUpload;

                field(name; 'Name')
                {
                    FileUploadAction = ProductImageUpload;
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {
            fileUploadAction(ProductImageUpload)
            {
                Caption = 'Upload product Image';

                AllowMultipleFiles = false;
                AllowedFileExtensions = '.jpg', '.jpeg', '.png';

                trigger OnAction(files: List of [FileInfo])
                var
                    currentFile: FileInfo;
                    stream: InStream;
                begin
                    foreach currentFile in files do begin
                        currentFile.CreateInStream(stream);
                        // Code here to handle the file
                        Message('%1 has a length of %2', currentFile.FileName, stream.Length);
                    end;
                end;
            }
        }
    }
}

You can start adding support for multiple file uploads in your apps to have File Upload Dialog support multiple files.