cancel
Showing results for 
Search instead for 
Did you mean: 

ASA 17.0.10: Question about calling external web services and passing binary data to them

Stalker4
Explorer
0 Kudos
245

Hi,

There is some external web service. I need to call it and pass binary data to it.
For this purpose I have created my own procedure:

CREATE PROCEDURE "dba"."WebTest2Run"( in "data" long binary,in "cAccessToken" long varchar,in "nCustomerID" integer,in "filename" char(20) ) 
result( "cAttribute" long varchar,"cValue" long varchar,"npp" integer ) 
url 'http://OtherSite/WebTest1'
type 'HTTP:POST:application/pdf'
header 'Authorization: !cAccessToken; \x0AContent-Disposition: form-data; name="nCustomerID" !nCustomerID; \x0AContent-Disposition: form-data; name="files"; filename="!filename"'

I call it like this:

 select * from dba.WebTest2Run(MyBinaryData, 'MyToken', 47, 'test.pdf')
 where cAttribute = 'Body'

 I need "Content-Disposition" to be specified twice in the header.

Content-Disposition: form-data; name="nCustomerID" 47 
Content-Disposition: form-data; name="files"; filename="test.pdf" 

But for some reason the second "Content-Disposition" setting overrides the first one, i.e. only the second setting remains in the header:

Content-Disposition = form-data; name="files"; filename="test.pdf"

 Is there any way to fix this ?

And another question: When calling an external web service and passing binary data to it, is it possible to make http-header as in the picture below ?

photo_2024-12-13_11-07-00.jpg

In particular I am interested in the "boundary" and "muiltipart" parts of the http header ?

Accepted Solutions (1)

Accepted Solutions (1)

PCollins
Participant

You need to do multipart for multiple Content-Dispositions and put them within the body parts, you can do it like this:

 

url 'api.endpoint.com'
set 'HTTP(EXCEPTIONS=off; VERSION=1.1)'
type 'HTTPS:POST:multipart/form-data'
header 'Connection:keep-alive \x0AAccept: */* \x0AContent-Type: multipart/form-data; boundary=XXXXboundary'

 

Then in your body you will need to list each of the boundaries for each part such as  

 

'--XXXXboundary\x0D\x0AContent-Disposition: form-data; name="@"; filename="' || @fileName || '"\x0D\x0A\x0D\x0A' || replace(replace(@csvData,',0,',',0.01,'),',.',',0.') || '\x0D\x0A--XXXXboundary--'

 

Hope this gets you going in the right direction.

 

Stalker4
Explorer
0 Kudos

Where do the numbers next to "boundary" come from ?

PCollins
Participant
0 Kudos
you can use whatever you want for the boundary string, see https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
Stalker4
Explorer
0 Kudos
I understand correctly that I will have to recode binary data into BASE64 (Function BASE64_ENCODE) ? P.S. I honestly thought that if you pass long binary data to a web function (in my example WebTest2Run), the recoding will be done automatically, as well as adding the necessary parts of the request header and body. But judging by your answer I was wrong.
PCollins
Participant

This is how I have got it working, ultimately however you do it, in whatever language, you will need the client to conform, I guess you might have just use languages that have libraries available where someone else has done all this as reusable code?

Personally I like have full control over the raw transmission.   

You will need to use whatever encoding the endpoint is expecting, it isn't always BASE64. 
You can read more about encoding here: https://www.w3.org/Protocols/rfc1341/5_Content-Transfer-Encoding.html

But yes if you haven't stored the data in your tables BASE64 encoded and they want BASE64 encoded you will need to use BASE64_ENCODE()

Answers (0)