Hi, I am trying to render ZPL code in my application using Labelary API. I have a image component that has binding on source prop. This binding is as follows:
I tried to convert it in similar way I did it wil images from database but I used SQL to do the base64 conversion. In this case a get a some result which seems to be invalid.
I used Base64.encodeBytes() method. Now the result looks like a base64 string but it still wont render in Image component.
I was suspecting that the data the POST request returned were modified by Ignition so I tried to save the PNG data to a .png file. It seems the data are not correct and I cannot display the image file in Windows.
The code I used to get the png for saving is below:
URL = "http://api.labelary.com/v1/printers/12dpmm/labels/5.82677x8.26772/0/"
contentType = "application/x-www-form-urlencoded"
headers = {
'Accept': 'image/png',
'Content-Type': 'application/x-www-form-urlencoded'
}
res = system.net.httpPost(URL,
contentType = contentType,
postData = ZPL,
headerValues = headers,
throwOnError = False
)
filename = system.file.saveFile("image.png")
if filename is not None:
system.file.writeFile(filename, str(res))
I wanted to do the same but since i cannot pass my ZPL as URL params, I have to use POST and send the ZPL as data. With that one cannot use iframe or image component.
The reason I have to use POST instead of GET is that my ZPL contains image data and the ZPL gets too long for URL.
oh, yeah, most of my labels don't use graphics, I just got one the other day that does have graphics and yeah, the IFrame didn't work. They are so few and far between I was just able to not worry about it. So will probably be reviewing this post someday assuming it all gets worked out
That would would be plan C. I will try using the Http client as suggested and write the png data into temp file (system.file.getTempFile). Then display it using the Image component. If that doesn´t work, I will try pdf.
Why a bunch of apache HTTP client imports over system.net.httpClient? GPT driven development?
Any non Java standard library import you use is subject to change and risks breaking on major or minor version upgrade. Using system.net.httpClient is guaranteed to be supported.