Skip to main content
14-Alexandrite
Nov 10, 2023 6:53 AM UTC
Solved

Convert blob data to String ( and vice versa )

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}

 

 

 

Rocko
RockoAnswer
19-Tanzanite
Mar 20, 2024 9:57 AM UTC

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.

8 replies

17-Peridot
Nov 15, 2023 1:33 PM UTC

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

 

Translate
14-Alexandrite
Nov 15, 2023 9:53 PM UTC

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

 

Translate
17-Peridot
Nov 16, 2023 10:42 AM UTC

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

Translate