store base64 string as image

Discussion forum about all things Team Developer 5.x and 6.x
Claudia
Germany
Posts: 4
Joined: 16 Jan 2019, 13:28
Location: Volkach, Germany

store base64 string as image

Post by Claudia » 16 Jan 2019, 15:24

Hello,

I'm creating a html-pages which contains a picture-stream as base64-string. For the conversion I used CryptBinaryToString- function of crypt32.dll - based on an example from these Forum ;-) and it works fine.

Now, I have to receive an base64 String, convert and store it as image-File (jpg). I tried to do it with CryptStringToBinaryA(). It looks not to bad - the length of the result string is > 0 - but I cannot show the image at a Picture-Container or store it.

Is there any example or sample I can have a look?

Thank you very much !

(By the way - I'm using Version 6.3)

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2928
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: store base64 string as image

Post by Dave Rabelink » 16 Jan 2019, 16:10

Could you post a small testcase here?

You can put the Base64 encoded string in a separate file and the TD source you are now using to convert the Base64 string to JPG.
ZIP it and put as attachment.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Harald
Germany
Posts: 144
Joined: 30 Mar 2017, 06:16
Location: Oberhaching/Munich, Germany

Re: store base64 string as image

Post by Harald » 16 Jan 2019, 16:19

Hello Claudia,

I don't use crypt32.dll, I have my own conversion dll, but first of all I would check if the file contains a valid image, a JPG-file should start with "ÿØÿà<nul><dle>JFIF<nul>". Do you have the original file to check size and content? Maybe it is truncated at a null byte. In this case ensure you use Long String instead of String for all operations, that is often the reason of such trouble.

Kind regards
Harald

Claudia
Germany
Posts: 4
Joined: 16 Jan 2019, 13:28
Location: Volkach, Germany

Re: store base64 string as image

Post by Claudia » 17 Jan 2019, 08:49

I made an test.app which contains both conversions (Picture to base64 and base64 to Picture) .
The zip-file also includes a jpg-file and a file containing the base64String of this Image.
You do not have the required permissions to view the files attached to this post.

thomas.uttendorfer
Site Admin
Site Admin
Germany
Posts: 198
Joined: 05 Mar 2017, 17:19
Location: Munich Germany

Re: store base64 string as image

Post by thomas.uttendorfer » 17 Jan 2019, 09:39

Hi Claudia,
you have to use the Function CryptStringToBinaryW - the Unicode-Version.

And there is a mistake in the parameter declaration of this function. The strings have to be LPWSTR instead of LPSTR.

Code: Select all

Function: CryptStringToBinaryW
	Parameters
		String: LPWSTR
		Number: DWORD
		Number: DWORD
		String: LPWSTR
		Receive Number: LPDWORD
		Receive Number: LPDWORD
		Receive Number: LPDWORD
Then it works for me.

Regards Thomas
Thomas Uttendorfer
[ frevel & fey ] Software-System GmbH
https://thomasuttendorfer.wordpress.com/

Claudia
Germany
Posts: 4
Joined: 16 Jan 2019, 13:28
Location: Volkach, Germany

Re: store base64 string as image

Post by Claudia » 17 Jan 2019, 09:53

Hi Thomas,

it really works! Great!
Thank you very much for investing time to check it out!

Claudia

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests