Sending images between Wintel and IBM i with JSON

Any IBM i topic that does not fit in another forum
Post Reply
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Sending images between Wintel and IBM i with JSON

Post by bbunney »

I'm working on a modernization project where the UI is now done in .Net on Wintel and the rest on IBM i. The apps communicate through web services using JSON and YAJL. Is it possible to send images back and forth between .Net and RPG through a web service using JSON? I know binary files aren't allowed in JSON. If it was just Wintel, the binary data (image) could be converted to text using Base64 and sent/received. Not sure about the ASCII/EBCDIC translation either. I know, not a good idea as the JSON payload will be much larger. But I need to tell management the options. I want to just send the URL for it back and forth storing the images on the IFS.
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: Sending images between Wintel and IBM i with JSON

Post by jonboy49 »

You can certainly Base64 encode your images and package them in a json response. If you were going to do that I would consider storing the base64 encoded value in a table on the IBM I rather than convert each time the image is requested.That way you only have to encode once when first storing (or updating) an image.

Another option would be to set up a "web service" mapping to the image files. No logic needed - Apache does all the work for you.

This brings me to another option. In many ways, the IFS is not a good place to store image files performance-wise. If there is significant image traffic then a lot of companies use a third-party service to host images. That is a particularly good option if world-wide access is required as the service provider has the option to cache the images at multiple locations which allows for faster "local" access.
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Sending images between Wintel and IBM i with JSON

Post by bbunney »

Thank you so much for your response. I'm very interested in the "web service" mapping to the image files options you provided. So I will look into it and see if I can find some documentation and/or examples.
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: Sending images between Wintel and IBM i with JSON

Post by jonboy49 »

Basically, all you need to do is to set up an Apache instance and associate it with a port number (let's say 1234). If your images are currently in (say) /productdata/images then you would set that as the Apache document root. Once that is in place test with a browser to http://yoursystemname/imageofproductX.jpg or whatever the filename is. The image will be delivered. Less than 5 minutes work, assuming you don't have a firewall blocking ports etc.

P.S. In terms of speed you might be better off using NGINX instead of Apache since you don't need to run any code on the IBM I side. It runs in PASE and can be installed via the ACS Open Source support. The rest of what I said still applies.
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Sending images between Wintel and IBM i with JSON

Post by bbunney »

Okay thank you. I will try it. I appreciate it.
Post Reply