Send image through rest adapter

jamesmcfly

New Member
Hello,
I am wondering how I can send image to progress database using the rest adapter. Currently I am developing a mobile app for iOS and sending image would be one of the features.
In the database, the images are stored as BLOB, which is not supported by Rest Adapter (CMIIW). The only way I can think of is to send the image as LONGCHAR (using base64EncodedString in iOS) and convert it to BLOB in the server side. It works, but the image would only correctly appear when using iOS devices. If I try to COPY-LOB the image from the database to an image file in computer, the image will not appear, but the size is correct. I believe that the encoding is not compatible.
Does someone has some experience with this situation? I still want to store the image as BLOB in server, but I haven't found the way to send the images from iOS, so that the image can be read on both computer and iOS.

Thank you
 

mollyfud

Member
Hey Mate,
This was discussed on the Progress Community a while back and I can't remember what you can't do exactly but the answer was that you could send a blob field in a temp-table. I looked for the code I used and have misplaced (with machine change over) the dataset/temp-table definition but I believe it was a temp-table (possibly wrapped in a dataset although this might not of been needed) with two fields: Fieldname as char and ImageBlob as a Blob field.
I then created a business entity off of that and the code in the create was this:
--------------------------
METHOD PUBLIC VOID CreatebeCam(INPUT-OUTPUT TABLE ettImage):
DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
DEFINE VARIABLE lcFile AS longchar NO-UNDO.
DEFINE VARIABLE mp AS MEMPTR NO-UNDO.
for each ettImage:
cName = "c:\temp4\" + ettImage.imageName.
lcFile = ettImage.imageBlob.
lcFile = substring(lcFile,24,-1).
mp = base64-decode(lcFile).
copy-lob mp to File cName.
end.
/* TODO: Add code to create a record from data passed
in from the client. */
END METHOD.
=================
Now admittedly this doesn't store it in a real table but once the temp-table is on the AppServer works, storing it in the database is trivial.
From memory the substring gets rid of code that is used on the web that isn't needed when trying to create the file on disk as an image file.

I will add another post in a minute with the Mobile AppBuilder part of this (if I still have it and can find it! ;-) ).
 

mollyfud

Member
Okay, so for starts, this was a test App so no laughing at the crappy design!!!!!!!! ;-)
Page layed out like this:
55ihog.jpg

And the Data services look like this:
r0tqig.jpg

(in order: Login Service, Device Camera service, JSDO JSDO obj, JSDO Create call)

Camera's request mapping like this:
efihj4.jpg


And response like this:
igj6vc.jpg

(So store/show the image code in Image widget (so you can see it), In the text area (debugging) and in a Local Variable (to use later from memory))

The Add call looks like this:
3095xl5.jpg

So take the filename you enter and then put the image code into the blob field.

The events on the design page are:
2yulx08.jpg

So on load, login. When take photo called, call the camera service. When load to the service, try to load it to the server by first initialising the JSDO. (this might have been a bug and should be done earlier but again, test app to prove point).

And lastly the data page events:
2dbkjsl.jpg

Not sure the first one. Second one sets local value. third one is if the JSDO call worked (when we pressed send it to the server) we call the Add service. Last two error handling.

And thats that. Not sure it helps or not (or this post with so many images will work or not)
 

mollyfud

Member
PS. The code of the image at the top looks like this:
-----------------------
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAMABAADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8
==============
(there is more gobbly gook but have cut it out as my last post was bigger enough as it is).
So notice the first 24 odd characters. Found that on the web they make the image work (and so on the mobile app that is basically a webpage in a webbrowser container) but to get it to show on my windows machine stripping it out worked.

Oh, and you have to run this as a native app on a device from memory as the Camera only works on these.

Hope this helps.
 

jamesmcfly

New Member
Thanks a lot for your answer!
I am actually create the iOS app natively and not using the progress mobile appBuilder, so there is no way I could send a temp-table with BLOB field in it. Btw. the code "mp = base64-decode(lcFile)." was very helpful. I didn't realise there is "base64-decode/encode" method.
I have successfully sent the code of the image like your example to the server as a NSString (char or longchar in Objective C) and decode it in the server side, so the binary could be save into the database and later the image could be shown both on iOS and computer. I have taken many pictures and it works!

Thanks a lot!
 

mollyfud

Member
Thanks a lot for your answer!
I am actually create the iOS app natively and not using the progress mobile appBuilder, so there is no way I could send a temp-table with BLOB field in it. Btw. the code "mp = base64-decode(lcFile)." was very helpful. I didn't realise there is "base64-decode/encode" method.
I have successfully sent the code of the image like your example to the server as a NSString (char or longchar in Objective C) and decode it in the server side, so the binary could be save into the database and later the image could be shown both on iOS and computer. I have taken many pictures and it works!

Thanks a lot!

Glad to hear this helped somewhat. Just for interest sakes, you can call the REST side of the Business Entity without the JavaScript side of it directly. Thats how the JSDO talks to the AppServer with the Business Entity but if you have it working, no reason to change it now! ;-)
 
Top