1. Yasir Masood
  2. PowerBuilder
  3. Monday, 6 January 2020 16:25 PM UTC

Hi,

I am using the following code to read data from a web service. However, i get the same Picture every time.

How do i clear the Blob to get the new picture?

I am using PB 2018 R3 Build 1858.

Thanks

http = create httpclient
li_rc = http.ClearRequestHeaders ( )
http.AutoReadData = false

http.setrequestheader('X-API_KEY',is_api_key)
http.setrequestheader('X-CompanyName',is_cust_no)
http.setrequestheader('X-UserName',is_user_id)

li_rc=0
li_rc = http.sendrequest( 'GET', ls_url)

IF li_rc = 1  and http.GetResponseStatusCode() = 200 THEN

    DO WHILE True
      li_rc = http.ReadData(lblb_NextData, 1024*16)
      if li_rc = 0 then exit // Finish receiving data
      if li_rc = -1 then exit // Error occurred
      if li_rc = -2 then exit // Timed out
      iblb_photo += lblb_NextData
    LOOP
ELSE
    MessageBox('Error','Unable to view th picture at this time.')
    Return
END IF

 

Yasir Masood Accepted Answer Pending Moderation
  1. Monday, 6 January 2020 20:10 PM UTC
  2. PowerBuilder
  3. # 1

I think i have figured it out, you can try this solution. This is working for me

Instance variable

Blob         iblb_photo[]

Blob        lblb_NextData

ls_pic_id = this.GetItemString(row,"pic_id")

ls_url = is_url + 'FileDownload/' + ls_pic_id

http = create httpclient
li_rc = http.ClearRequestHeaders ( )
http.AutoReadData = false

http.setrequestheader('X-API_KEY',is_api_key)
http.setrequestheader('X-CompanyName',is_cust_no)
http.setrequestheader('X-UserName',gv_user_id)

li_rc=0
li_rc = http.sendrequest( 'GET', ls_url)

IF li_rc = 1  and http.GetResponseStatusCode() = 200 THEN

    DO WHILE True
      li_rc = http.ReadData(lblb_NextData, 1024*16)
      if li_rc = 0 then exit // Finish receiving data
      if li_rc = -1 then exit // Error occurred
      if li_rc = -2 then exit // Timed out
      iblb_photo[row] += lblb_NextData
    LOOP
ELSE
    MessageBox('Error','Unable to view the picture at this time.')
    Return
END IF

p_image.show()
p_image.originalsize=false
p_image.setpicture(iblb_photo[row])

Comment
  1. Ricardo Jasso
  2. Tuesday, 7 January 2020 15:32 PM UTC
Both cases seem to be part of a function with row as an argument. The difference is that in the first case the instance blobl variable never gets reset while in the second case a blob array is used with row as the index. But I think that if it tries to read the picture using the same row again it will have the same problem as in the first case.
  1. Helpful
  1. Miguel Leeuwe
  2. Tuesday, 7 January 2020 21:27 PM UTC
I guess you're right. The " += " suggests the picture has to be read in more than one loop, but it's my impression that that's not happening at all. Maybe I'm misinterpreting the whole thing.

Thanks Ricardo.
  1. Helpful
  1. Ricardo Jasso
  2. Tuesday, 7 January 2020 23:07 PM UTC
I tried the example from the PowerBuilder documentation and it works perfectly fine. The difference in Yasir's first case is that he is using an instance variable instead of a local variable to store the blob. So the next time the function is called it'll keep adding up to the blob variable. The ideal thing to do is to reset the instance blob variable before the loop but setting it to null will prevent it from adding data since concatenating data to a null variable will result in null. It needs to be initialized like when it is first created with an initial size of zero. The only way I think of doing this is declaring a local blob variable without assigning any value to it and then copying that variable to the instance variable.
  1. Helpful
There are no comments made yet.
Yasir Masood Accepted Answer Pending Moderation
  1. Monday, 6 January 2020 19:32 PM UTC
  2. PowerBuilder
  3. # 2

Chris,

I have tried setting the blob variable to null, but that only result in no data being returned.

Instance Variable

Blob         iblb_photo

Local Variable

Blob        lblb_NextData
Blob         lblb_null

SetNull (lblb_null)

lblb_NextData = lblb_null    //reset
iblb_photo = lblb_null    //reset

http = create httpclient
li_rc = http.ClearRequestHeaders ( )
http.AutoReadData = false

http.setrequestheader('X-API_KEY',is_api_key)
http.setrequestheader('X-CompanyName',is_cust_no)
http.setrequestheader('X-UserName',is_user_id)

li_rc=0
li_rc = http.sendrequest( 'GET', ls_url)

int li
li=http.GetResponseStatusCode()
string ls_res
ls_res = http.GetResponseStatusText()

IF li_rc = 1  and http.GetResponseStatusCode() = 200 THEN

    DO WHILE True
      li_rc = http.ReadData(lblb_NextData, 1024*16)
      if li_rc = 0 then exit // Finish receiving data
      if li_rc = -1 then exit // Error occurred
      if li_rc = -2 then exit // Timed out
      iblb_photo += lblb_NextData
    LOOP
ELSE
    MessageBox('Error','Unable to view the picture at this time.')
    Return
END IF

 

Comment
  1. Chris Pollach @Appeon
  2. Monday, 6 January 2020 19:50 PM UTC
Hi Yasir;

In that case, I suspect that the Web Service might have an issue OR its also possible that your binary data is being returned to your PB App Base64 encoded. You'll need to check with the WS authority.

Regards ... Chris
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 6 January 2020 18:36 PM UTC
  2. PowerBuilder
  3. # 3

Hi Yasir;

  You can clear a blob variable as follows:

  • Blob  lblb_data
  • Blob  lblb_null
  • SetNull (lblb_null)
  • // Some Processing
  • lblb_data = lblb_null    //reset

HTH

Regards ... Chris

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 6 January 2020 17:16 PM UTC
  2. PowerBuilder
  3. # 4

I've tried to run the example from the powerbuilder help on ReadData:

Examples

Integer li_rc
Blob lblb_photo, lblb_NextData
HttpClient lnv_HttpClient 

lnv_HttpClient = Create HttpClient

// Not to read data automatically after sending request (default is true)
lnv_HttpClient.AutoReadData = false

// Send request using GET method
li_rc = lnv_HttpClient.SendRequest("GET", "http://demo.appeon.com/PB/webapi_client/employee/102/photo")

// Receive large data
if li_rc = 1 and lnv_HttpClient.GetResponseStatusCode() = 200 then
 do while true
  li_rc = lnv_HttpClient.ReadData(lblb_NextData, 1024*16)
  if li_rc = 0 then exit // Finish receiving data
  if li_rc = -1 then exit // Error occurred
  lblb_photo += lblb_NextData
 loop
end if


Same thing's happening to me: no 'next' data seems to be found, always the same data.
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.
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.