Skip to main content
14-Alexandrite
November 10, 2023
Solved

Convert blob data to String ( and vice versa )

  • November 10, 2023
  • 1 reply
  • 6120 views

Hi Developers,

 

I'd like to convert blob data to string and convert to string data to blob.

 

may I get your help to do the above ?

 

let blob_data = LoadBinary( { path : "/image.png" } );

//convert blob data to string to write it to SQL

let str_data = {something function for the conversion}

 

 

 

Best answer by Rocko

The "trick" is SaveBinary accepts base64 encoded values for content as shown in https://www.ptc.com/en/support/article/CS212085.

Check here for an example.

1 reply

16-Pearl
November 15, 2023

Hey,

normally you would use base64 functions to achieve this. Use Encode to convert to string and decode to return to binary. But I could not get it to work as I would like.

 

Maybe the ptc article https://www.ptc.com/en/support/article/CS335717 helps as some starting point.

They use the snippets available in Composer:

nmutter_0-1700055126011.png

 

14-Alexandrite
November 15, 2023

Hi 
Thank you for your response.

I've created a test service to check if the resolution in the link you shared with me, but failed.

I expected to get original image but image data cannot be  restored.

 

I'd be happy someone help me on this.

 

YoshihikoN_0-1700084988001.png

 

16-Pearl
November 16, 2023

Yes that's where I had the issue too. But you see in line 12 it changes your binary data and wraps {array:xxx} around it.

After decoding you would need to reverse this operation as well, to get only your xxx back. But I did not try it further for now