Getting image in bytes and wanted to display on channel's HDPoster as jpeg image
I'm getting the following request from postman for the Poster image of my channel.
Postman Request
I do research and found that the image I'm getting is in byteArray/roBitmap and I have to display it in Poster Image by parsing it from JSON. How do i can parse and get its link to show it on HDposter ?
'The Following is the code to get responce, response = fetch({
url: m.global.baseUrl + "/" + item.id + "/poster?w=100&h=100",
timeout: 30000,
method: "GET",
headers: {
"X-API-TOKEN": "c1cf45d8-73de-4467-9d33-802b00d27ed9"
}
})
if response.ok
_response = response.json()
? _response
end if
'The following is the fetch function to parse image from JSON
function fetch(options)
timeout = options.timeout
if timeout = invalid then timeout = 30000
response = invalid
port = CreateObject("roMessagePort")
request = CreateObject("roUrlTransfer")
request.SetCertificatesFile("common:/certs/ca-bundle.crt")
request.InitClientCertificates()
request.RetainBodyOnError(true)
request.SetMinimumTransferRate(1, 60)
request.SetMessagePort(port)
if options.headers <> invalid
for each header in options.headers
val = options.headers[header]
if val <> invalid then request.addHeader(header, val)
end for
end if
if options.method <> invalid
request.setRequest(options.method)
end if
request.SetUrl(options.url)
requestSent = invalid
if options.body <> invalid
requestSent = request.AsyncPostFromString(options.body)
else
requestSent = request.AsyncGetToString()
end if
if (requestSent)
? requestSent
msg = Wait(timeout, port)
status = - 999
body = "(TIMEOUT)"
headers = {}
if (Type(msg) = "roUrlEvent")
status = msg.GetResponseCode()
headersArray = msg.GetResponseHeadersArray()
for each headerObj in headersArray
for each headerName in headerObj
val = {
value: headerObj[headerName]
next: invalid
}
current = headers[headerName]
if current <> invalid
prev = current
while current <> invalid
prev = current
current = current.next
end while
prev.next = val
else
headers[headerName] = val
end if
end for
end for
body = msg.GetString()
if status < 0 then body = msg.GetFailureReason()
end if
response = {
_body: body,
status: status,
ok: (status >= 200 and status < 300),
headers: headers,
text: function()
return m._body
end function ,
json: function()
return ParseJson(m._body)
end function ,
xml: function()
if m._body = invalid then return invalid
xml = CreateObject("roXMLElement")
if not xml.Parse(m._body) then return invalid
return xml
end function
}
end if
return response
end function