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

How to store base64 string as binary?

uskalviskis
Participant
0 Likes
4,457

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

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Likes

Sorry for joining the party late! What seems to be the confusion here?

XSD Datatype of BinaryObject is Base 64 Binary which means that you don't have to do anything if your webservice is sending the base64 encoded data inside FileContent of AttachmentFolder. When such calls reach ByD, it will be saved as a proper FileAttachment!

You don't have to create a Binary Object from a base64 value with your absl coding! Pls see the below screenshot.

uskalviskis
Participant
0 Likes

Problem at least temporally is solved. As I thought ParseFromString is not that function on which we can relay when we need to decode base64 string to binary. So there was made code fix from backed for now adding function which actually decodes base64 string to binary.

So I really hope that in future Binary library could be updated with new fuction which decodes base64 string back to binary.

Best regards,
Uldis

Former Member
0 Likes

Hello Uldis,

I have a similar problem.

I want to pass the binary-content to Adobe Livecycle Designer for printing an image dynamically.

That will work if I get the binary data somehow in the XML. Because the AttachmentFolder is not filled in the XML I want to make a customer field an move the binary into it.

I need the binary representation as a hexadecimal string like I see it in the debugger. A base64-coded string will work also. But at the moment I'm not able to do anything with binaryObject.content.

Is there any way to move it to an LANGUAGEINDEPENDENT_EXTENDED_Text field in my xbo?

If I fill my field manually from the UI everything works fine, but I need the binary content to fill it automatically. Any ideas?

kind regards,

Frank

Former Member
0 Likes

As there is no way that you can use a BinaryObject in an xbo, the question you asked is valid.

So, lemme ask if you tried the below thing already? make sure that your binary content will be no more than 255 characters else it will be trimmed out. Please let us know your progress here when you try.

Former Member
0 Likes

Today I switched to 1402 and tried ToBase64String. It does exactly what I need. In my opinion I have no restriction to 255 characters. I use LANGUAGEINDEPENDENT_EXTENDED_Text in my xbo and specially for xbo this type is unlimitted in length.

By the way, the test shell in Studio 1402 is not able to show the content of my LANGUAGEINDEPENDENT_EXTENDED_Text-Field, it's always empty.

But I get the base64 data in my xml and the form is printing the image.

Thank's a lot for your hint. 🙂

kind regards,

Frank

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

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello Uldis,

If Attachment is the name of the DO Attachment and you've already created an instance, would this code below do the job?

import ABSL;

import BASIS.Global;

  

var DataFromWebService : BinaryObject;

DataFromWebService.content = <...>      // from WebService

var BinaryObject = this.Attachement.Document.GetFirst().FileContent.BinaryObject;

BinaryObject.content = DataFromWebService.content;

  

HTH,

    Horst