1. Sivaprakash BKR
  2. PowerBuilder
  3. Friday, 14 July 2023 05:13 AM UTC

Hello

Using PB 2022 B 1900, Postgresql 15

Need to update image in a database field (bytea datatype).   Need to send the image along with the key field(s).  How to send it?  
Weng through https://community.appeon.com/index.php/qna/q-a/using-rest-client-to-send-file (Using REST client to send file (appeon.com).  The solution given doesn't include the key values to update the image into the database.

Another code, that I got somewhere from the web is

HttpClient lnv_Http
Constant Long BlobPartLen = 65536
Blob lblb_PostData, lblb_PostPart
Integer li_rc, li_PartNum
String ls_ServerURL

li_rc = lnv_Http.PostDataStart(ls_ServerURL)
If li_rc = 1 Then
	// post the data in parts
	do while li_rc = 1
		lblb_PostPart = BlobMid(lblb_PostData, li_PartNum * BlobPartLen + 1, BlobPartLen)
		li_rc = lnv_Http.PostData(lblb_PostPart, BlobPartLen)
		li_PartNum ++
	loop
	lnv_Http.PostDataEnd()

	// get results
	ll_StatusCode = lnv_Http.GetResponseStatusCode()

	If ll_StatusCode = 200 Then
		// HTTP status 200 = OK
	Else
	End If
End If

I think using the above code, we could send the image.   
1.  No idea about how to send the key values?  
2. What to set in the RequestHeader?.   We used to set it as  lo_client.SetRequestHeader('Content-Type', 'application/json')
3.  If we need to send both key values (as JSON) and Image [ so that both could be received at server side to update the required field in the database ], what could be the settings?

Or any other way(s) available to achieve this?

Happiness Always
BKR Sivaprakash

 

mike S Accepted Answer Pending Moderation
  1. Sunday, 16 July 2023 13:55 PM UTC
  2. PowerBuilder
  3. # 1

Were you given a REST API endpoint for sending the blob to?   If you were, then you should have been given the endpoint and all the required headers, required structures in the body, security connections, etc.  If you were given any of that, then it is up to the provider of the api to provide you with that information.  

 

Are you connecting to the Postgresql 15 database from your application?  The fact that it is 'in the cloud' doesn't mean anything.  no different that connecting to a remote database via vpn.  you would just be doing an updateblob.

 

 

Comment
There are no comments made yet.
Daryl Foster Accepted Answer Pending Moderation
  1. Friday, 14 July 2023 05:47 AM UTC
  2. PowerBuilder
  3. # 2

First question is what are you sending the file and key values to?  Have you created a web api that will receive them and update the database?  If it were me I'd create an api that accepts a multipart form post where you can send the file and the associated data.

The example in this post https://community.appeon.com/index.php/qna/q-a/problem-passing-xml-to-web-api-using-httpclient#reply-33648 does that.  It just passes the file as an xml string, but the same concept applies with a binary file, you just need the correct Content-Type header in your form data file part to match your file type.

In my code I just use SendRequest, but if the file is really large you could use code similar to what you've posted and use the PostDataStart, PostData and PostDataEnd to send the blob.

If you want to update the Postgresql database directly from Powerbuilder I don't think you would be using http unless Postgresql has it's own api.  To update the database directly you'd just use Powerbuilder's standard database features.

Comment
  1. Miguel Leeuwe
  2. Friday, 14 July 2023 08:08 AM UTC
In addition to what Daryl says: Why not simply do an UPDATEBLOB from powerbuilder.
  1. Helpful
  1. Sivaprakash BKR
  2. Friday, 14 July 2023 13:42 PM UTC
Thanks Daryl Foster

Content-Disposition: So far no idea about this settings. Will try to set required one.



Miguel: Database is in the cloud. Need to send the image as binary and then update the same into a database. For local database, UpdateBlob works fine.

  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.