cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Image into base64 format in SAP MDK

akashgongal
Explorer
0 Kudos

Hi Experts,

I am trying to implement an attachment functionality through MDK using media action where we have a requirement to convert that attached image into base64 format and send it to the backend using Action.Type.ODataService.CreateMedia action.

Could you please give some guidelines to achieve this?

Thank you

Accepted Solutions (0)

Answers (2)

Answers (2)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

CreateMedia expects the media content in binary form not base64. You can certainly get the base64 string for content and convert but that would not then be passed into any of the OData media or stream actions.

Can you share the $metadata for your media entity you are trying to populate?

akashgongal
Explorer
bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

I see the entity showing as hasStream=true to indicate it is a media entity. However, for a media entity you do not need the url property since the media (binary) will be stored in the entity (not within a property) assuming this is odata v2. The odata media actions will handle the creation / access to the binary media without needing the url property.

Please confirm with your odata service team as to what and how the url property is being used.

evanireland
Advisor
Advisor
0 Kudos

I'm not an MDK user but if you use some custom JavaScript code perhaps you can use the btoa(...) function.

See https://developer.mozilla.org/en-US/docs/Glossary/Base64