1. iliyan iliev
  2. PowerBuilder
  3. Tuesday, 11 July 2023 12:57 PM UTC

How to replicate this request

curl --location 'http://localhost:34020/api/processor' \
--header 'IE-INTERFACE_VERSION: 1.11' \
--header 'IE-SERVER_TYPE: BGExtractor' \
--header 'IE-JOB_ID: 42' \
--header 'IE-RESULT_TYPE: PNG' \
--header 'IE-PROCESSOR: Main' \
--form 'Source=@"/C:/Users/cyriaksh/Pictures/Faces/nina_hibsch.jpg"' \
--form 'Background=@"/C:/Users/cyriaksh/Pictures/1pxWhite.png"'
Accepted Answer
Andreas Mykonios Accepted Answer Pending Moderation
  1. Tuesday, 11 July 2023 13:14 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi.

Take a look at the following conversation: HTTPClient (appeon.com).

Andreas.

Comment
  1. René Ullrich
  2. Tuesday, 11 July 2023 13:53 PM UTC
One more hint: Because you have to send two files you need an additional section separated by the "Boundary".
  1. Helpful 3
  1. iliyan iliev
  2. Wednesday, 12 July 2023 11:35 AM UTC
Files who i send NOT BASE64. could this be a problem?!
  1. Helpful
  1. René Ullrich
  2. Wednesday, 12 July 2023 11:55 AM UTC
No. You can send data and files as blob (as shown in the linked example).
  1. Helpful 1
There are no comments made yet.
iliyan iliev Accepted Answer Pending Moderation
  1. Thursday, 13 July 2023 12:55 PM UTC
  2. PowerBuilder
  3. # 1
long ll_FileNum
blob blb_file_source,blb_boundary,blb_terminus,blb_multipart,blb_file_bg
integer li_rc,li_ResponseStatusCode
HTTPClient lnv_HttpClient
string ls_endpoint ,  ls_file, ls_ResponseBody,ls_ResponseStatusMessage


li_ResponseStatusCode = 0
ls_ResponseBody = ''
ls_ResponseStatusMessage = ''

// Hard code the file name and endpoint for testing
ls_file = 'D:\pics\vesko.jpg'
ls_endpoint = 'http://localhost:34020/api/processor'
// Create a boundary marker for the multipart blob
string ls_Boundary = "$$$Boundary$$$"
// Read the file into a blob
blb_file_source = filetoblob(ls_file)
// Create component blobs
blb_boundary = blob('~r~n--' + ls_Boundary + '~r~n', EncodingUTF8!)
blb_file_source = blob( 'Content-Disposition: form-data; name="Source"; filename="vesko.jpg"~r~n' + "Content-Type: image/jpg~r~n~r~n", EncodingUTF8!) + blb_file_source
ls_file =  'D:\pics\dot.png'
blb_file_bg = filetoblob(ls_file)
blb_file_bg = blob( 'Content-Disposition: form-data; name="Background"; filename="dot.png"~r~n' + "Content-Type: image/pgn~r~n~r~n", EncodingUTF8!) + blb_file_bg
blb_terminus = blob('~r~n--' + ls_Boundary + '--~r~n', EncodingUTF8!)
// Concatenate blobs into a single multipart blob
blb_multipart = blb_boundary + blb_file_source+ blb_boundary+blb_file_bg+ blb_terminus
// Send the request
lnv_HttpClient = create HTTPClient

lnv_httpClient.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" + ls_BOUNDARY)
lnv_httpClient.SetRequestHeader("Accept-Encoding","gzip, deflate, br")
lnv_httpClient.SetRequestHeader("Connection","keep-alive")
lnv_httpClient.SetRequestHeader("IE-INTERFACE_VERSION","1.11")
lnv_httpClient.SetRequestHeader("IE-SERVER_TYPE","BGExtractor")
lnv_httpClient.SetRequestHeader("IE-JOB_ID","111")
lnv_httpClient.SetRequestHeader("IE-RESULT_TYPE","JPG")
lnv_httpClient.SetRequestHeader("IE-PROCESSOR","Main")
li_rc = lnv_httpClient.SendRequest('POST', ls_endpoint, blb_multipart)
// obtain the response data
if li_rc = 1 then
	li_ResponseStatusCode = lnv_HttpClient.GetResponseStatusCode()
	ls_ResponseStatusMessage = lnv_HttpClient.GetResponseStatusText()
	lnv_HttpClient.GetResponseBody(ls_ResponseBody, EncodingUTF8!)
	if li_ResponseStatusCode = 200 then
		MessageBox('Upload Successfull', ls_ResponseBody)
	else
		MessageBox('Upload Failed', ls_ResponseBody)
	
	end if
	
else
	MessageBox('HTTP Error', 'Error calling ' + ls_endpoint + '. Return Code ' + string(li_rc))
end if

Rest service give me error 406 - not acceptable ?! What is wrong ?!

Comment
  1. Arnd Schmidt
  2. Thursday, 13 July 2023 15:53 PM UTC
Content-Type: image/pgn ?
  1. Helpful
  1. Daryl Foster
  2. Friday, 14 July 2023 00:54 AM UTC
I agree with Arnd, that would be a good place to start. Your Content-Type in this line should be image/png, not image/pgn



blb_file_bg = blob( 'Content-Disposition: form-data; name="Background"; filename="dot.png"~r~n' + "Content-Type: image/pgn~r~n~r~n", EncodingUTF8!) + blb_file_bg



Another difference between your code and your curl example is your are setting the IE-RESULT_TYPE header to JPG in your code but PNG in your curl call
  1. Helpful
  1. iliyan iliev
  2. Friday, 14 July 2023 07:12 AM UTC
Thanx :) Syntax Error :) Is works :)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.