Convert image to string without losing data in c++


Convert image to string without losing data in c++



I am sending data from my C++ client to C# WCF service where it accepts JSON data.



We need to send an image to WCF service by converting it to a JSON string, but while converting image (jpg/jpeg) it has some null characters inside a string () so the string is getting terminated when converting std::string to char* and I am able to send only part of the string to service. Is there way that I can convert the image to string (const char *) without having null characters in it so that I can send all the image data (as char*) without loosing any data?



std::string


char*


const char *


char*



The available function from C++ client is:


httpClient.POST("ServiceName", const char* data, "ContentType")





Convert to base64
– Aram
Jun 28 at 13:10





You should not create a "string" from the raw binary data. Instead you use some encoding scheme that is textual but can handle arbitrary binary data. One such common encoding scheme is base64.
– Some programmer dude
Jun 28 at 13:10





Convert the data to hex or base64 first.
– Retired Ninja
Jun 28 at 13:10





use an array of uchar of known size
– petacreepers23
Jun 28 at 13:24





Converting to base64 has worked. Thanks
– NDestiny
Jun 29 at 13:53









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages