on 2024 Apr 04 8:05 AM
In BTP ABAP Environment, I have a RAP entity with an action. Let's call the action 'generateFile'. In that action, I have specific logic that uses the XCO classes to build out an XLSX file. The RAP entity and its action are projected and exposed into a Fiori Elements application. The action is triggered from a user pressing a button.
The final step is that the XLSX file that is generated needs to be automatically downloaded to the user's frontend. Is there a way of doing that from the action itself? Or do I need to handle this from the Fiori app (meaning, no way to test the action from the OData service preview)?
Request clarification before answering.
Ended up using this in the RAP action implementation:
DATA(lv_base64_content) = cl_web_http_utility=>encode_x_base64( lv_file_content ).
Then passed the base64 content and the filename to the frontend.
An enhancement was then needed on the frontend, which is roughly:
const mimeType = 'application/vnd.ms-excel';
let blobContent = atob(base64Content);
let byteNum = new Array(blobContent.length)
for (var i = 0; i < blobContent.length; i++) {
byteNum[i] = blobContent.charCodeAt(i);
}
let byteArray = new Uint8Array(byteNum);
let excelBlob = new Blob([byteArray], { type: mimeType.toLowerCase() });
FileUtil.save(excelBlob, fileName, "xlsx", mimeType);
where FileUtil is alias for 'sap/ui/core/util/File'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @MattDion, Great implementation! Could you elaborate on how you passed the base64 content and filename from the RAP action to the frontend? Sharing insights on this process would be incredibly helpful for others working on similar RAP scenarios!
User | Count |
---|---|
60 | |
10 | |
8 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.