Attachments upload from UI5/FIORI Applications
Attachments that come from any front end application can be saved in the backend server in case DMS or any archive server is not in place. The attachments are converted as raw string and stored in a z table.While reading this raw string is again converted back.
I take up this scenario from my current project where we were required to upload the invoice file while creating a Vendor Disbursement Request Order from the front end SAPUI5 application.
Here are the arrangements that we need to make initially at the backend in order to smoothen this flow.
- Create a z table ZMEDIA in our example with the following fields.
- In the service builder tcode SEGW check the media checkbox for this entity
The parent Entity is DisHeader that shows up in the above screenshot. This shall contain the disbursement request that gets created as a result of payload data we pass from the frontend. The relevant attachment has to be associated for each of these disbursement requests.
In order to achieve the upload functionality we implement the method CREATE_STREAM of the data provider class.
In this method we directly upload the attachment in table ZMEDIA. We use a slug parameter to pass the key fields. In our case, while we create the disbursement Request from the frontend we would first upload the attachment. Here we pass a slug parameter that is the file name which would act as a key field to store the attachment in ZMEDIA. Then we pass the payload for disbursement number generation. In the same payload, we pass the filename we had uploaded in the earlier step, in one of the fields (CREA_STATUS). After the disbursement number is generated we query ZMEDIA table with the filename that we sent in the payload (in the field CREA_STATUS) to check whether a similar entry exists. If an entry is found we associate the new disbursement number with the file, delete the existing record with the same filename from ZMEDIA and create a new record with disbursement number in the key field.
Now let’s see the actual scenario with debug screenshots to elucidate the above facts.
Debug screenshot of Method CREATE_STREAM.
Screenshot from Table ZMEDIA after attachment Upload.