Sending picture via HTTPRequest

Discussion forum about all things Team Developer 7.x
alisa.nua
Thailand
Posts: 8
Joined: 10 Aug 2017, 08:24
Location: Thailand

Sending picture via HTTPRequest

Post by alisa.nua » 31 Aug 2017, 06:24

How to send a picture into SOAP body?
I try to send a string using the code below but it does not work :

Code: Select all

Call SalFileOpen( hFile, "close_16.bmp", OF_Read | OF_Binary )
Call VisFileSeek( hFile, 0, SEEK_End )
Set nPicByteSize = VisFileTell( hFile ) 
Call VisFileSeek( hFile, 0, SEEK_Begin) 
Call SalFileRead( hFile, sPic, nPicByteSize )
Call VisFileClose( hFile )
Set sXMLParameterBody = '<TestGetPicString xmlns="http://tempuri.org/">
			<Pic>' || sPic || '</Pic></TestGetPicString>'
The result of sXMLParameterBody is :
sXMLParameterBody = '<TestGetPicString xmlns="http://tempuri.org/">
<Pic>䵂̶"'
This part '</Pic></TestGetPicString>' is missing and I cannot call the webservice.

I cannot find other solutions, any thoughts?

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

Sending picture via HTTPRequest

Post by Dave Rabelink » 31 Aug 2017, 08:34

The issue is that you concatenate the image data (which is binary) into your overall string.
This will never work as binary data contains NULL values and will cut off the resulting string up to the NULL character.

How it should be done is purely dependent on how the server (the webservice) expects the image data to be handled.
So, you first have to read the documentation about the webservice how the image data has to be provided.
There are several implementations possible, so you client must use the one the webservice demands.

Probably the image data has to be provided as Base64 encoding. This is a string representation of the data.

Example Base64 encoded string:

Code: Select all

VEhJUyBJUyBBIFRFU1Q=
When the image has to be provided as Base64, you have to convert the sPic variable contents first from binary to Base64.
Use the WinApi for that, explained here:

https://msdn.microsoft.com/en-us/librar ... s.85).aspx


Fortunately, there is already a TD sample for this, have a read here:

http://wiki.tdcommunity.net/index.ph ... ryToString

When the sPic value is converted and stored in sPicBase64 variable, you can concatenate it in the SOAP message.
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

alisa.nua
Thailand
Posts: 8
Joined: 10 Aug 2017, 08:24
Location: Thailand

Sending picture via HTTPRequest

Post by alisa.nua » 31 Aug 2017, 09:32

I was going for Base64 encoding at first but I don't know how to convert it using Gupta function.
I will try to follow the samples.

Thank you Dave.

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

Sending picture via HTTPRequest

Post by Dave Rabelink » 31 Aug 2017, 09:44

alisa.nua wrote:
31 Aug 2017, 09:32
I will try to follow the samples.
As a quick start:

- Download the sample WIKI_CryptBinaryToString.zip for the needed functions
- Include this file in your project : PALCryptBinaryToString_UNICODE.apl

Then use this code to convert your sPic to sPicBase64:

Code: Select all

Call PALCryptBinaryToString( sPic, CRYPT_STRING_BASE64, sPicBase64 )
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

alisa.nua
Thailand
Posts: 8
Joined: 10 Aug 2017, 08:24
Location: Thailand

Sending picture via HTTPRequest

Post by alisa.nua » 31 Aug 2017, 10:44

I got it Dave. Thank you!!!

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2069
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Sending picture via HTTPRequest

Post by Jeff Luther » 31 Aug 2017, 15:16

Alisa - FYI, I have several crypto-type samples on my TD page: http://www.jeffluther.net/TD/#Code_Samples

Dave gave you a Base64 solution already, but you or others might find others of my crypto samples to be handy as well. The samples should work for any TD version through v7.
Jeff Luther @ PC Design
Palm Springs, California
TD info. & samples: http://www.jeffluther.net/TD/

alisa.nua
Thailand
Posts: 8
Joined: 10 Aug 2017, 08:24
Location: Thailand

Sending picture via HTTPRequest

Post by alisa.nua » 08 Sep 2017, 09:28

I find many of them very useful.
Thank you Jeff.

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2069
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Sending picture via HTTPRequest

Post by Jeff Luther » 13 Sep 2017, 16:22

You are welcome, Alisa. Happy to help!
Jeff Luther @ PC Design
Palm Springs, California
TD info. & samples: http://www.jeffluther.net/TD/

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests