Hi Alex,
I analyzed your code and the issue is with the code parsing in PB Client.
Since the result set format sent from Web API to PowerBuilder is:
{
"photo": {
"Size": 21331,
"Length": 21331,
"Value": "R0lGODlh8"
}
}
It still needs to parse it after retrieving the photo value and the value of the “Value” Key is what we need.
There are two methods below to retrieve the value of the “Value” Key:
Method #1: Parse several times using the JSONPackage method to get the value of the “Value” Key (I added two lines of code marked in red based on your code):
[PB Client]
inv_RestClient.SendGetRequest("http://localhost:5000/api/Sample/F_get_picture/70", ls_data)
ljp_data = Create JSONPackage
ljp_data.Loadstring(ls_data)
ls_photo = ljp_data.GetValue("photo")
ljp_data.Loadstring(ls_photo)
ls_photo = ljp_data.GetValue("Value")
lnv_CoderObject = Create CoderObject
lb_pic = lnv_CoderObject.Base64Decode(ls_photo)
//Or
//lb_pic = blob (ls_photo)
p_1.setpicture(lb_pic)
Method #2: Parse once with the new feature provided by JasonParser in PowerBuilder 2019 R3 to get the value of the “Value” Key:
[PB Client]
inv_RestClient.SendGetRequest("http://localhost:5000/api/Sample/F_get_picture/70", ls_data)
//ljp_data = Create JSONPackage
//ljp_data.Loadstring(ls_data)
//ls_photo = ljp_data.GetValue("photo")
JsonParser lnv_JsonParser
String ls_Path
lnv_JsonParser = Create JsonParser
lnv_JsonParser.LoadString(ls_data)
ls_Path = "/photo/Value"
ls_photo = lnv_JsonParser.GetItemString(ls_Path)
lnv_CoderObject = Create CoderObject
lb_pic = lnv_CoderObject.Base64Decode(ls_photo)
//Or
//lb_pic = blob (ls_photo)
p_1.setpicture(lb_pic)
Regards,
David
Finally I tried sending just the PbBlob object from the controller and it works perfectly as well.
In PB Client the code would look like this:
inv_RestClient.SendGetRequest("http://localhost:5000/api/Sample/f_get_picture/70", ls_data)
ljp_data = Create JSONPackage
ljp_data.LoadString(ls_data)
ls_photo = ljp_data.GetValue("Value")
lnv_CoderObject = Create CoderObject
lb_pic = lnv_CoderObject.Base64Decode(ls_photo)
p_1.setpicture(lb_pic)
Alex