You can enable users to upload files to a server.
When the upload functionality is enabled, the user can do the following:
-
Upload files either by dragging and dropping them onto the table, or by clicking the Upload button
-
Download the uploaded files by clicking on the file name in the table
-
Delete the uploaded files by selecting the lines and clicking on the Delete button, or by using the table's context menu
Uploading and deleting is only available in edit mode.
To prevent security issues and protect data from being created or processed with malicious content, you must ensure the following security measures are in place:
Define
@Core.AcceptableMediaTypesto specify allowed file types.The back-end service framework must ensure a virus scan and other security measures, such as maximum file size limitations and MIME-type restrictions, are in place.
You must also implement file validation and data sanitization in the back end.
For more security-related information, see Security Configuration.
To enable upload functionality, ensure the following prerequisites are met:
-
The entity type must have an
Edm.Streamtype property that is used to store the uploaded file. -
The
UI.LineItemannotation must contain a reference to theEdm.Streamtype property that is used to store the uploaded file. -
The entity type must have the
UI.MediaResourceannotation with theStreamproperty referencing theEdm.Streamtype property that is used to store the uploaded file.
Here is an example of how to define the entity type with the required annotations:
XML Annotation
<Annotations Target="Namespace.EntityType"> <Annotation Term="UI.LineItem"> <Collection> <Record Type="UI.DataField"> <PropertyValue Property="Value" Path="PropertyOfEdmStreamType"/> <PropertyValue Property="Label" String="File"/> </Record> </Collection> </Annotation> <Annotation Term="UI.MediaResource"> <Record Type="UI.MediaResourceType"> <PropertyValue Property="Stream" Path="file"/> </Record> </Annotation> </Annotations>
ABAP CDS Annotation
No ABAP CDS annotation sample is available. Please use the local XML annotation.
CAP CDS annotation
You can use the
Attachmentsplug-in to define the entity type. For more information about the plug-in, see Attachments.
For more information and live examples, see the SAP Fiori development portal at Building Blocks - Table - Upload Table.
You can add additional columns and actions to the table by either defining further UI.LineItem annotations or by adding custom columns and actions into the manifest.json file, as described in Defining Line Items.
You can control the visibility and the enablement of the Upload button in the same way as you can control the Create button for any other table. A new instance is created through uploading a file, so the Upload button has the same semantic meaning as the Create button. For more information about controlling the visibility and enablement of the Create button, see Adding Actions to Tables.
The back-end service framework must ensure a virus scan and other security measures, such as maximum file size limitations and MIME-type restrictions, are in place.
You can restrict the file type and the size of the files to be uploaded with the MaxLength and Core.AcceptableMediaTypes annotation, as described in Enabling Stream Support.