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

How to store base64 string as binary?

uskalviskis
Participant
0 Likes
4,462

Hi all cloud developers,

currently I'm facing issue to which I can't find solution. I get through web service call binary content as base64 string. I want to store it as attachment in cloud. But currently seems like there is no possibility to do that.

First I thought that Binary.ParseFromString() function could solve this issue but now I understood that it's used differently.

Does anybody of you faced this issue and found solution?

Thanks,
Uldis

View Entire Topic
uskalviskis
Participant
0 Likes

Hi Horst,

this approach I've tried and thats why I had this question because with following approach we will get following error "Assignment of the type 'String' to the type 'Binary' is not possible."

There is missing some kind of base64 decode function, because Binary library allows us only encode binary to base64 string.

BR,
Uldis

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello Uldis,

Did you get this error during runtime or in the ABSL editor?

It reads to me that you have a String data type so you use your approach with Binary.ParseFromString().

What about setting the other attributes of the BinaryObject liek "characterSetCode"?

Bye,

   Horst

uskalviskis
Participant
0 Likes

Hi Horst,

Following error will appear in ABSL editor.

When I use Binary.ParseFromString() I'll get errors when I try to open those attachment files, that content is corupped. I assume ParseFromString is used only to covert text content, i.e, html content.

Example for my binary object content:

     cpBinary.content = Binary.ParseFromString(impBase64);

     cpBinary.fileName = "recievedfile.pdf";

     cpBinary.characterSetCode = "utf-8";

     cpBinary.mimeCode = "application/pdf";

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello Uldis,

I 've got no error in the ABSL editor with the cde from above.

What is the definition of "cpBinary"?

Bye,

  Horst

uskalviskis
Participant
0 Likes

Hi Horst,

if you are using ParseFromString you won't get an error.

cpBinary is BinaryObject.

This will go through. But when I add this binary object to DO Attachment and try to open the file I'll get error that file is corrupted or it's not PDF. This error you will get when you are opening downloade file on your computer.

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello Uldis,

Sorry, I mixed it up: What's the type of impBase64?

Bye,

  Horst

uskalviskis
Participant
0 Likes

impBase64 contains value from web service response so it's interpreted as string. As I mentioned earlier web service returns base64 encoded string.

Former Member
0 Likes

Hi Udis,

the particular choice of character set selected for the 64 characters required for the base varies between implementations.

So try to do a reverse engineering, using the stringToBase64 function, what is the C4C implementation, and modify your ws accordingly.

uskalviskis
Participant
0 Likes

Hi Alessandro,

with stringToBase64 function you mean Binary function ToBase64String? If yes then I can't understand your idea, because for this function import value should be Binary.

Can you show with simple example what was your idea?

Thanks,
Uldis

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello Uldis,

When do you access the file:

  • In the same sesssion before Save
  • In the same session after Save
  • In a new session

Reason:

I've talked to the Attachment colleagues  and depending on that they access their original buffer, modified buffer or must read from DB. They told me that may be the reason.

Please test.

Bye,

   Horst

uskalviskis
Participant
0 Likes

Hi Horst,

I tested all three scenarios and result was same. I'm not sure that this would be a reason.

Binary is saved in attachement folder with structure what I assigned to BinaryObject when I parsed base64 string to binary. After that using creatFile action I added it to Attachment Folder.

BR,
Uldis

Former Member
0 Likes

Hi,

you are right. I thought that the input was a string.

You can try all the codification types listed in the table:

Base64 - Wikipedia, the free encyclopedia

Or you can ask SAP people what kind of codification they use

Former Member
0 Likes

Hi,

where do I find the ToBase64String function?

I need to convert the base64 binary to base64 string.

Didn't find anything like that.

kind regards,

Frank