cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How do I pass the raw data as content for Attachment API_DOCUMENT_SRV

VijayDaniel
Explorer
0 Kudos
965

I have a requirement for an application I've developed where, upon clicking an attachment, the camera opens, allowing the user to take a picture and send it to the SAP S4 system. The issue arises when sending the data to SAP: although I'm passing it in Base64 format and it is stored correctly against the document number attachments, attempting to open the file results in a "file not supported" error.

our landscape application developed in Neptune open edition-->goes through API suite to S4

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
SAP Mentor
SAP Mentor
0 Kudos

Please check out my example https://github.com/gregorwolf/bookshop-demo/blob/main/tests/app/api-cv-attachment.http on how to use the API. You can't directly attach the base64 string. The image must be attached as a binary body. Maybe also my sample project https://github.com/gregorwolf/ZBPSERVICE also can help you.

VijayDaniel
Explorer
0 Kudos
Hi Gregorw, Thanks for your reply. I am using Neptune DXP open edition tool for developing the UI. I created server script with the below logic and it worked const { image, slug, contentType, BusinessObjectTypeName, LinkedSAPObjectKey } = req.body; log.info(req.body); // Create a Buffer from a Base64 encoded image string. // The `Buffer.from()` method converts the Base64 string into binary data that can be used as the body of a request. var buffer = Buffer.from(image, "base64"); const opts = { headers: { Slug: "script6_file.jpeg", "Content-Type": "image/jpeg", BusinessObjectTypeName: BusinessObjectTypeName, LinkedSAPObjectKey: LinkedSAPObjectKey, }, body: buffer, }; console.log(opts); //complete(); try { // Send api request. const response = await apis.AttachmentContentSet(opts);
gregorw
SAP Mentor
SAP Mentor
0 Kudos
It's too bad that comments do not allow nice formatting. I would suggest you ask in the Neptune Forums instead.
VijayDaniel
Explorer
0 Kudos
Hi Gregorw, Issue is fixed now. I am able to store the pic in S4 :). Thanks a lot for your time.

Answers (2)

Answers (2)

VijayDaniel
Explorer
0 Kudos

Yes I am using API_CV_ATTACHMENT_SRV V1.0

AndreasMuno
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you for your question, @VijayDaniel.

You might prefer for the user to take a picture in a BTP web app or even simply use their mobile phone to send the picture to your app's storage space using any of the built-in transmission capabilities. That way you could focus on storing the image in a suitable corporate file folder (a private cloud file store?) and send a hyperlink from there to the proper space in S/4 from where users with respective authorization can access the image file in the folder when clicking on the attachment icon. 

The SAP system itself does not make for a proper file system for storing images. That is not its purpose and design. It might do a poor job and yet be rather expensive for the amount of data. When you do your research you might find proper (online, private) data storage fit for purpose at a fraction of the cost. 

If this addresses the core of your question, please mark the response accordingly. Thank you.   

VijayDaniel
Explorer
0 Kudos
Hi Thank you very much for your reply. I agree how ever my business case is we're developing a proof-of-delivery application. When a user scans the delivery document barcode, it retrieves the document's details. The driver then takes a picture, which is sent to S4 and stored as an attachment to the corresponding delivery document number. While I can successfully send the attachment in Base64 format and save it, attempting to open the file results in an 'unsupported file' error.