CLOB Data on iSeries

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
lawingo
Posts: 56
Joined: Fri Dec 04, 2015 6:41 am

CLOB Data on iSeries

Post by lawingo » Thu Aug 24, 2017 4:36 am

I'm working on a simple VL-Web project of capturing an image via tablet(Camera Control Widget) and saving the image to an iSeries File as CLOB data. I have a pre-existing identical project that works but the data is saved in a Windows SQL Server. I assume once I have the CLOB data saved I should be able to retrieve it and view it on the Web as well as any regular VL application that is running against the iSeries. I have created a test application for each but I can't get the image to show in either one.
I save the image data into a CLOB by deconstructing the base64 data into 65000 byte chunks

Code: Select all

Evtroutine Handling(#CameraControl.Completed) Base64data(#base64) File(#file)
* Define_Com Class(#EMEM_SM01.InsertEMEM) Name(#EMEMInsert)

* #SYS_WEB.Alert Caption(#base64)
#Image1.FileName := #base64
#W_LENGTH := #base64.CurSize

Clr_List Named(#L_IMG64)
#W_START := 1
#W_END := 65000
Dountil Cond(#W_END = #W_LENGTH)

#W_BLOBH := #base64.Substring( #W_START #W_END )
Add_Entry To_List(#L_IMG64)

#W_START := #W_START + 65000
#W_END := #W_END + 65000

If Cond(#W_END > #W_LENGTH)
#W_END := #W_LENGTH
#W_BLOBH := #base64.Substring( #W_START #W_END )
Add_Entry To_List(#L_IMG64)
Leave

Endif

Enduntil



Endroutine
Then in my Server Module I put it all back together and insert it into the file:

Code: Select all

Srvroutine Name(InsertEMEM)
List_Map For(*INPUT) List(#L_EMEM) Parameter_Name(TheList)
List_Map For(*INPUT) List(#L_IMG64) Parameter_Name(ImgList)

Field_Map For(*OUTPUT) Field(#EMEMID) Parameter_Name(id)
Field_Map For(*OUTPUT) Field(#W_STATUS) Parameter_Name(Status)

Get_Entry Number(1) From_List(#L_EMEM)

#EMEMID := 0

Use Builtin(STM_FILE_OPEN) With_Args('/tmp/EMEM.txt' 'Write LineTerminator=NONE') To_Get(#STSTGRJP)
* Use Builtin(STM_FILE_OPEN) With_Args('c:\temp\emem.txt' 'Write LineTerminator=NONE') To_Get(#STSTGRJP)

Selectlist Named(#L_IMG64)
Use Builtin(STM_FILE_WRITE) With_Args(#STSTGRJP #W_BLOBH)
Endselect
Use Builtin(STM_FILE_CLOSE) With_Args(#STSTGRJP)

#EMEIIMG := '/tmp/EMEM.txt'
* #EMEIIMG := 'c:\temp\emem.txt'

Insert Fields(#EMEMID #EMEMDVID #EMEMCTID #EMEMDPID #EMEMJTCD #EMEMHRDT #EMEMLVDT #EMEMI_D #EMEMRATE #EMEMATFL) To_File(EMEM) Io_Status(#W_STATUS) Io_Error(*NEXT) Val_Error(*NEXT) Return_Rrn(#PRIFILRRN)

Fetch Fields(#EMEMID) From_File(EMEM) Io_Error(*NEXT) Val_Error(*NEXT) With_Rrn(#PRIFILRRN)

Insert Fields(#EMEMID #EMEIIMG) To_File(EMEI) Io_Status(#W_STATUS) Io_Error(*NEXT) Val_Error(*NEXT)

* Use Builtin(OV_FILE_SERVICE) With_Args('REMOVE_FILE' '/tmp/EMEM.txt')
* Use Builtin(OV_FILE_SERVICE) With_Args('REMOVE_FILE' 'c:\temp\emem.txt')

Endroutine
To View the Image I am doing the following in the Server Module:

Code: Select all

Srvroutine Name(GetWebImagesv2)
Field_Map For(*INPUT) Field(#EMEMID) Parameter_Name(ID)
List_Map For(*OUTPUT) List(#L_VIMG64) Parameter_Name(ImgList)

Clr_List Named(#L_VIMG64)

* Fetch Fields(#EMEMID) From_File(EMEMVU1) With_Key(#EMEMCTID) Io_Error(*NEXT) Val_Error(*NEXT)

Fetch Fields(#EMEIIMG) From_File(EMEI) With_Key(#EMEMID) Io_Error(*NEXT) Val_Error(*NEXT)
#DVDVID := #EMEMID

Use Builtin(STM_FILE_OPEN) With_Args(#EMEIIMG.FileName 'Read') To_Get(#STSTGRJP)
Dountil Cond((#FW_RETCD <> 'OK') And (#FW_RETCD <> 'OV'))
Use Builtin(STM_FILE_READ) With_Args(#STSTGRJP) To_Get(#W_BLOBH #FW_RETCD)
Add_Entry To_List(#L_VIMG64)
Enduntil
Use Builtin(STM_FILE_CLOSE) With_Args(#STSTGRJP)

#LISTCOUNT += 1
Add_Entry To_List(#L_EMEM)

Endroutine
And then I am preparing it for the screen as this:

Code: Select all

Mthroutine Name(GetDetail) Access(*PRIVATE)
Define_Map For(*INPUT) Class(#EMEMCTID) Name(#miEMEMCTID)
Define_Com Class(#emem_SM01.GetDetail) Name(#GetDetail)
Define_Com Class(#emem_SM01.GetWebImagesv2) Name(#GetImage)

#GetDetail.Execute Contactid(#miEMEMCTID) Thelist(#L_EMEM)

Get_Entry Number(1) From_List(#L_EMEM)

* Get Image
#GetImage.Execute Id(#EMEMID) Imglist(#L_VIMG64)

#base64 := *null
Selectlist Named(#L_IMG64)
#base64 := #base64 + #W_BLOBH
Endselect

* #SYS_WEB.Alert Caption(#EMEMID.AsString + ' ' + #EMEMCTID.AsSTring + ' ' + #base64)

#Image1.Image <= #SYS_APPLN.CreateBitmap( #base64 )

#Image1.FileName := #base64

Endroutine
A few more helpful tidbits:
  • When I select the record in the test application it acts like its trying to load
  • I can preview the re-assembled CLOB data
But in the end - I don't see my image. This same set up works great on the Windows Web Server but not using the iSeries. Any suggestions?

Best,
Chad

dhnaigles
Posts: 47
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Re: CLOB Data on iSeries

Post by dhnaigles » Thu Aug 24, 2017 4:55 am

Chad,
Why a CLOB and not a BLOB? I have been using BLOB fields to save images from a mobile device and store them on the iSeries. Also, on what device and through what method are you displaying the image? are you putting it in an image control on a VL webpage or displaying in a #PRIM_WEB control? If it is in a #PRIM_WEB control, take a look at the discussion thread "PDF Viewer in VL Web"

User avatar
lawingo
Posts: 56
Joined: Fri Dec 04, 2015 6:41 am

Re: CLOB Data on iSeries

Post by lawingo » Thu Aug 24, 2017 5:15 am

The camera Control only allows Base64 Data. The File Picker allows you to save a BLOB but not the camera control widget. I would have preferred a BLOB but this was how I was advised on my original project. I have attempted to set up one method but two different platforms of displaying the image. The first being an image control within a regular VL application (my VLF). The 2nd is an image control on a VL Web page.

dhnaigles
Posts: 47
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Re: CLOB Data on iSeries

Post by dhnaigles » Thu Aug 24, 2017 5:24 am

Sorry, I have not tried the camera control widget. I preferred to use the FilePicker. It works just fine on both iOS and Android devices and gave me the functionality I needed. Can I ask - Why use the camera control? Does it have some additional functionality that the FilePicker does not?

User avatar
lawingo
Posts: 56
Joined: Fri Dec 04, 2015 6:41 am

Re: CLOB Data on iSeries

Post by lawingo » Thu Aug 24, 2017 5:42 am

I work in Furniture Manufacturing. In my original project, the user wanted to take photos of the furniture before they were packed and shipped. Using the camera Control Widget, I was able to allow the user to take the picture and save it without saving it to the Camera Roll. This seemed important since the User was going to take at least 4 images per piece of furniture. That would add up quickly. Also, it seemed more efficient to take the image from the VL Web page than taking the image and then switching back to Lansa Mobile APP to pick the image and save it.

Regardless of the use, I have the process working with a Windows Server and it works well. I'm baffled at why its not working with our iSeries.

dhnaigles
Posts: 47
Joined: Wed Feb 03, 2016 1:34 am
Location: Marlborough, MA, USA

Re: CLOB Data on iSeries

Post by dhnaigles » Thu Aug 24, 2017 6:43 am

Chad
When you use the file picker on a mobile device, it gives you the option to "Take Photo or Video" and returns the BLOB to the VL Web Page. Take a look at my attachments
Attachments
result of filepicker taking a picture.png
result of filepicker taking a picture.png (391.65 KiB) Viewed 2672 times
popup of filepicker click.png
popup of filepicker click.png (250.3 KiB) Viewed 2672 times

User avatar
lawingo
Posts: 56
Joined: Fri Dec 04, 2015 6:41 am

Re: CLOB Data on iSeries

Post by lawingo » Thu Aug 24, 2017 9:57 pm

Why didn't you lead with that ?? :D I'm not sure what lead me to think the FilePicker wouldn't do that. Thanks!

caseywhite
Posts: 110
Joined: Thu May 26, 2016 1:17 am

Re: CLOB Data on iSeries

Post by caseywhite » Fri Aug 25, 2017 1:14 am

In a previous post of mine here is what I had noticed with the behavior when using the File Picker. It works nicely but at least on an Android device it doesn't recognize that the picture was taken in portrait module.

The File Picker is nice in that you don't have to run it in LANSA Mobile and the coding is easier. But it seems like you don't know if the picture was taken portrait so you would have to give the user the option to rotate the picture. But since it supports BLOB the coding of passing the BLOB field to the server module and reading the BLOB field is really easy. So it could be worth considering the file picker.

Post Reply