1. Vladimir K.
  2. PowerBuilder
  3. Wednesday, 7 February 2024 18:34 PM UTC

Hi all.

Need a little help here, newer done this before. Any help or steering in the right direction will be greatly appreciated.

Appeon Powerbuilder 2019R2 Build 2353.

Need to push .xml file using presigned url into s3 bucket using existing api

 

step 1 get presigned url

GET example from postman:

/*
curl -X 'GET'
'https://api-qa.xxxxxxx.io/api/mailing/v1/external/C3/order/upload-url'
-H 'accept: application/json'
-H 'Authorization: Bearer [long static string value stored in database]'
*/

Return:

{
"key": "xxxxx-unique-value-for additional-processing-xxxx",
"url": "https://s3.us-presigned url"
}

 

so i used HttpClient and now i have a "presigned url"

 

Step 2, send a file.

PUT example from postman:

curl 'presigned url'
-X 'PUT' \
-H 'Accept: */*' \
-H 'Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 41187' \
-H 'Content-Type: text/xml' \
-H 'Origin: https://xxxx-qa.xxxx.io' \
-H 'Referer: https://xxxx-qa.xxxx.io/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
--compressed

Return: just check for 200

So i did look up: https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html

Not match in there to help me, just command: curl -X PUT -T "/path/to/file" "presigned URL"

 

But i suspect i cannot read file into blob or string, then use HttpClientand and do something like:

lnv_HttpClient.sendRequest( "POST",presigned url, blob)

So what can i do?

Did see some examples using Chilkat but it is not an option.

 

Ones again any help and\or directions will be greatly appretiated.

Thank you

Vlad

 

Accepted Answer
Daryl Foster Accepted Answer Pending Moderation
  1. Wednesday, 21 February 2024 02:50 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Vlad, there was similar issue with the RestClient so there's a fair chance it affects the HttpClient as well.  There was an issue with long URLs which has been fixed in later versions of Powerbuilder.  Here is a link to someone with the similar problem:
https://community.appeon.com/index.php/qna/q-a/restclient-max-url-length

 

Comment
  1. Vladimir K.
  2. Wednesday, 21 February 2024 13:58 PM UTC
Thank you Daryl
  1. Helpful
There are no comments made yet.
Vladimir K. Accepted Answer Pending Moderation
  1. Wednesday, 21 February 2024 13:58 PM UTC
  2. PowerBuilder
  3. # 1

Thank you Daryl.

Comment
There are no comments made yet.
Vladimir K. Accepted Answer Pending Moderation
  1. Tuesday, 20 February 2024 19:25 PM UTC
  2. PowerBuilder
  3. # 2

Hi ALL.

I beginning to think, that there is something between http client and url i am passing to it.

I wonder if there is some kind of restriction/limitation on it.

I am running Appeon PB app, Postman and Fiddler side-by-side:

Upload file from Postman, attaching file from pc or posting string from FileReadEx() = (success)  - in the Fiddler, i can see what is "flying over a wire", headers, body etc.

Upload file from the our app using HttpClient = ( fail, return code = -2), client returns -2 immediately - in the Fiddler, i can NOT see anything, feels just like HttpClient.SendRequest("PUT", s_url, s_file_in_the_string) is NOT doing anything.

Here is the example of s_url:

https://s3.us-west-2.amazonaws.com/zz.zzzzzz.zz.files.stage/42f63e06-362f-40aa-9f5b-80809a417198?X-Amz-Security-Token=IQoJb3JpZ2luX2VjEEsaCXVzLXdlc3QtMiJHMEUCIDUF6BG3cJDnmLBNalKhEYLJBxTCccLAzU9h40vaNSgNAiEAqgYGPyP1Pc4oa2NKcL4gIzWnBCM%2F%2Fu6MY9kQg5po344qwwQINBAGGgwyMTM0MTUxOTEzOTMiDE4jbPGEwOYEEQUX7CqgBHA4UWWbWjZ1nHDNgJuE6sMvQkTYf2Qge%2Boo4ynr5ev0WnlB1KUEposScjR1IYBqFZlBLV4xJE2rFtv5LWuwolAx%2FXI3Ut0CzBVbq%2BjZXBZT9eHXnCKK4JQtLDC8yq7jt8NCEB3VqR%2FSz2UHU0tXBqOWKJ1%2FTaa8%2FO8tXN8pA7RrXRl1eFaCDKNNj1%2BD3ebZBeB1%2Fs%2B5aSEZzUFCmwbh9UszgM3SVslQlT14Iik7JXYLXqarB2O%2BM6LHAewxEA1PuMInIMu6lwd1%2B2W3dcQus2O2pyFtF1nFUxGa3Qh%2FitJyU6f861AF0Y4uks%2FSIEtSBIxTICiBklER410QdQu52ag%2BuJ5TKi4SbLdvwlAqpeomsrC1j5ZYNKp3ho9x3fq0%2BP%2BfT8%2FZP4%2BNYp%2BU5Gx35m7FZ%2F0qu57OCDReswqIqGT1cpILVfCktPi0rOM4B3RTP97XWVaGgAxid%2Bi%2BMx97Y4CnkF6QrYOz6M3hb%2FlbdWzNTiIF6alPuOk5s8f9UnvtSg0yFRnvlHpAdaKFMZnJL5M%2F2am48UCRTUGzQy6l31lF403dVvAXncsSEMlxlljA4kIxtJjnVedwt0JKm9qriLb0xiN0X%2BDmHTfKCS1Pz%2BYCH%2FY6xMeLUEbtGqdm7GniFju4EQKOFZK0KU2JzZYd%2BVr%2Fzd8DIfu8pu48O499siMzTEa0Hzt8xif%2BuU%2F8B7lrOCaTDF9%2BDCNT6weHOk0vq28ws%2FPTrgY6pgHowfbQ6r%2BD6XZFSjn4CTrn8Thv%2FwIALXCLDbFnK2gMlgzdBQfvF2boNAEwZYul7pLlsVbq%2BEz7wibzi7io4caJ9lfpVUAqwKw9eWhfnxbCPmO7Dtm6cHwOmbcV5Y%2FyTHb99un4JyX1OK8Ev9f3xov1JUgbmi5XGZlCct83y3ACZKCQkTNu1vWQ01WjPhNioC92xgjkpRS0KcLS8VSkta0McnEeshEw&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240220T191547Z&X-Amz-SignedHeaders=host&X-Amz-Expires=599&X-Amz-Credential=ASIATDMEJMNQSRVH3HU6%2F20240220%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Signature=b0b88d15f7f6a573c3c265353be8bf551f43b20e2f0ca5f129348899a9ba00c4

Upload file from the our app using Msxml2.XMLHTTP.6.0 and same s_url = (success) - in the Fiddler, i can see what is "flying over a wire", headers, body etc.

--select len(s_url) = 1602

Any recommendations?

Greatly appreciated.

Sincerely

Vlad

Comment
There are no comments made yet.
Vladimir K. Accepted Answer Pending Moderation
  1. Friday, 9 February 2024 15:53 PM UTC
  2. PowerBuilder
  3. # 3

Hi Rene.

Thank you for participation and willing to help, greatly appretiated.

This is not a "multipart/form-data" data

I got headers from Postman:

i_rc = lnv_HttpClient.setRequestHeader( 'Accept', '*/*' )
i_rc = lnv_HttpClient.setRequestHeader('Connection', 'keep-alive')
i_rc = lnv_HttpClient.setRequestHeader("Content-Length", string(len(blb_file)))
i_rc = lnv_HttpClient.SetRequestHeader("Accept-Encoding", "gzip, deflate, br")
i_rc = lnv_HttpClient.SetRequestHeader("Content-Type", "application/xml")

I also did try to use

POST - lnv_HttpClient.SendRequest("POST", presigned url, blob)

and

PUT - lnv_HttpClient.SendRequest("PUT", presigned url, blob)

getting -2 ( Invalid URL ) return in both cases.

So, there is something else i am missing.

 

BTW, i was always under impression that POST= Insert and PUT = Update, but i could be wrong.

Thank you

Sincerely

Vlad

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 8 February 2024 06:38 AM UTC
  2. PowerBuilder
  3. # 4

You can also upload files using HTTPClient but you have to build the body data to send and the request headers youself depending what the server expected.

Here you can find an example using multipart/form-data:

https://community.appeon.com/index.php/qna/q-a/httpclient-post-with-multipart-form-1?limitstart=0#reply-41133

BTW, in your posting you use POST instead of PUT in sendRequest!

Comment
There are no comments made yet.
Vladimir K. Accepted Answer Pending Moderation
  1. Thursday, 8 February 2024 02:36 AM UTC
  2. PowerBuilder
  3. # 5

Looks like Msxml2.XMLHTTP.6.0 came to the rescue ...

long l_FileNo, l_filelength, l_fileclose
blob blb_file

l_FileNo=fileopen("C:\my_file_name.XML",StreamMode!)

l_filelength=FileReadEx(l_FileNo,blb_file)

l_fileclose=FileClose(l_FileNo)

 

oleobject loo_xmlhttp
string s_status, s_response


loo_xmlhttp = CREATE oleobject
i_rc = loo_xmlhttp.ConnectToNewObject("Msxml2.XMLHTTP.6.0")

loo_xmlhttp.open("PUT", presigned url, false)


loo_xmlhttp.setRequestHeader("Content-Disposition","attachment; filename=my_file_name.XML")
loo_xmlhttp.setRequestHeader("Content-Length", string(len(blb_file)))


loo_xmlhttp.send(blb_file)

s_status = string(loo_xmlhttp.Status)
s_response = string(loo_xmlhttp.ResponseText)

 

got 200 back, file is in the bucket, downloaded file from the bucket, matched with one i send from my machine, have a full match.

hopefully it will help someone.

Still ... is there is better/different way to do it?

Thank you

Comment
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.