cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve file content from SAP MDK attachments

KazuhikoTakata
Active Participant
0 Kudos
395

Hi experts,

Last time I asked Steps to implement MDK application to upload photos to Document Management Service then got direction of implementation.

After that I implemented rule to call sendRequest using destination of Document Management Service (SDM) REST API. My application partially worked (folder created) so REST API connection is no problem now.

But when I uploaded photo file to SDM, uploaded content is not expected, binary like "[B@7cfe4c8".

My rule is below (some unnecessary parts for explanation are deleted). I manually created multipart/form-data body and header.

Based on the test result, I should not set variable fileContent directly to multipart body. But I could not find resolution. Could you give me some hint to solve this?

export default function CreateEntity(clientAPI) {
    const attachments = clientAPI.getControl('SectionedTable0').getControl('FormCellAttachment0').getValue();
    const fileContent = attachments[0].content;
    // some logic
    return clientAPI.executeAction({
        // action of creating folder to SDM : no problem
    }).then((r) => {
        // Generate multipart header and body
        const boundary = '----WebKitFormBoundary' + Math.random().toString(36).substring(2);
        let body = '--' + boundary + '\r\n';
        
        // some logic

        // Append file content to body => fileContent need to be changed
        body += 'Content-Disposition: form-data; name="media"; filename="' + filename + '"\r\n';
        body += 'Content-Type: ' + contentType + '\r\n\r\n';
        body += fileContent + '\r\n';    
        body += '--' + boundary + '--';
        
        // Set the headers
        const headers = {
            'Content-Type': 'multipart/form-data; boundary=' + boundary,
            'Content-Length': body.length
        };
        return clientAPI.executeAction({
            'Name': '/myApp/Actions/myEntity/myEntity_CreateFile.action',
            'Properties': {
                'Target': {
                    "Service": "/myApp/Services/sdm.service",
                    "Path": '/root/' + folderName,
                    "RequestProperties": {"Method": "POST", "Body": body, "Headers": headers}
                }
            }
        })
    });
}

Best regards,

Kazuhiko Takata

View Entire Topic
KazuhikoTakata
Active Participant
0 Kudos

Hi @manishmatte1753 ,

At that time, I changed strategy and used SAP Process Automation and SAP Document Management Service. Those are perfectly fit to my requirements.

manishmatte1753
Explorer
0 Kudos
so you called the BPA endpoint via MDK? or something else? please let me know as im also facing this issue, Thanks.
KazuhikoTakata
Active Participant
0 Kudos
No, I did not use MDK for this case, and used BPA form as my mobile entry UI.