Page 1 of 1

Continuing saving images Lansa mobile

Posted: Fri Oct 20, 2017 5:06 am
by atostaine
This thread shows how to get base64 from the camera into a CLOB.

viewtopic.php?f=3&t=1386&p=2861&hilit=image#p2908

I'm trying to get a BLOB though. How can I do that? Thanks

Re: Continuing saving images Lansa mobile

Posted: Tue Oct 24, 2017 1:34 pm
by atostaine
While I wait for SP2, I researched other options to convert the BASE64 to a BLOB. Python seemed simple enough, is available on V7Rx on i and most other platforms. Research IBM 5733OPS to install IBM's open source options.

The script below works great for me. I saved it in as /pyscripts/decodebase64.py. I'll wrap it in a function and call from my server module, then use the outputfile for my BLOB. I've never written python before and did all this tonight by googling.

You can run it from IBM i command line like this:
QSH CMD('python3 /pyscripts/decodebase64.py -i /tmp/image642.txt -o /tmp/image642_new.jpg')

[code
import base64
import sys, getopt

def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print ('decodebase64.py -i <inputfile> -o <outputfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ('decodebase64.py -i <inputfile> -o <outputfile>')
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg

input_file = open(inputfile, 'r')

coded_string = input_file.read()
decoded = base64.b64decode(coded_string)
output_file = open(outputfile, 'wb')
output_file.write(decoded)
output_file.close()

if __name__ == "__main__":
main(sys.argv[1:])

[/code]

Re: Continuing saving images Lansa mobile

Posted: Tue Oct 24, 2017 6:20 pm
by tsupartono
If you install EPC141070 (for SP1), you can use XPRIM_Binary to convert your Base64 string to bytes and write it to a file.
Assuming your Base64 data is in a variable called #MyBase64String, see example below.

Code: Select all

Define_Com Class(#XPRIM_Binary) Name(#BinaryData)

#BinaryData.FromBase64String String(#MyBase64String)

#STD_BLOB := #BinaryData.AsFile
You can find the documentation for XPRIM_Binary here:
http://docs.lansa.com/14/en/lansa015/in ... 0_0010.htm

Re: Continuing saving images Lansa mobile

Posted: Wed Oct 25, 2017 12:07 am
by atostaine
Thanks. USA tech support didn't know about this. I'll install it and check it out.

Art

Re: Continuing saving images Lansa mobile

Posted: Tue Nov 07, 2017 5:55 am
by lawingo
I originally posted the topic you referenced. Forget that original Post - Use the "File Picker". It is much simpler and will allow you save your images as BLOBs. The "CameraControl" Widget is a bit misleading. FilePicker does the exact same thing but allows you to use Blobs.

Code: Select all

Evtroutine Handling(#SelectFile.FileSelected) File(#File)

Signal Event(uSelectedImage) Selectedimage(#File.blob)
Endroutine

Evtroutine Handling(#webFilePicker.uSelectedImage) Selectedimage(#mImage)

#Image1.FileName := #mImage
#EMEIIMG := #mImage

Endroutine




Re: Continuing saving images Lansa mobile

Posted: Fri Nov 10, 2017 5:29 am
by atostaine
I need to scan barcodes also so I'm using LANSA Mobile. Is there a way to scan barcodes without it?

Thanks, Art

Re: Continuing saving images Lansa mobile

Posted: Tue Nov 14, 2017 7:09 am
by atostaine
tsupartono wrote: Tue Oct 24, 2017 6:20 pm If you install EPC141070 (for SP1), you can use XPRIM_Binary to convert your Base64 string to bytes and write it to a file.
Assuming your Base64 data is in a variable called #MyBase64String, see example below.

Code: Select all

Define_Com Class(#XPRIM_Binary) Name(#BinaryData)

#BinaryData.FromBase64String(#MyBase64String)

#STD_BLOB := #BinaryData.AsFile
You can find the documentation for XPRIM_Binary here:
http://docs.lansa.com/14/en/lansa015/in ... 0_0010.htm
How do I define the base64string? Previously I was using a PRIM_ALPH field to hold the base64 string.

Thank you.

Re: Continuing saving images Lansa mobile

Posted: Tue Nov 14, 2017 7:55 am
by tsupartono
You can still use PRIM_ALPH.

I noticed in the example I provided, the FromBase64String invocation is missing the String parameter name.
The String parameter name does need to be specified.
Please see the corrected code below.

Code: Select all

Define_Com Class(#PRIM_ALPH) Name(#MyBase64String)

#BinaryData.FromBase64String String(#MyBase64String)

Re: Continuing saving images Lansa mobile

Posted: Tue Nov 14, 2017 9:22 am
by atostaine
Thank you. I was using alt-space and searching the docs to try and figure out what was wrong. Another few hours maybe. :D

Re: Continuing saving images Lansa mobile

Posted: Thu Dec 07, 2017 4:53 pm
by VLNinja70
How are you guys getting your base64 variable up to the server from the client after you take the picture?
I can only talk to the server module from the web page using fields (limited to 65k)

Is there a way you can pass up the Prim object in one go to the server module or do you have to break it up into 65k bits in a list and rebuild the string on the server side to stuff it all into a blob?


AAAAAAnd Ok I totally see what you guys mean by the file picker being easier.... way cool 8-)

Re: Continuing saving images Lansa mobile

Posted: Thu Dec 14, 2017 8:43 am
by atostaine
Sorry missed this post.

It's held in the RP as a PRIM_ALPH, then it to send it up, substring into a list that has one entry per 64K.

The link that I posted earlier in this thread has Casey's example. Here is how I substring'd it out. Do the opposite in the server function.
#Current comes from an image collection because I'm sending multiple images up.

Code: Select all

#W_LENGTH := #current.CurSize
Clr_List Named(#imageList)
#W_START := 23
#W_END := 65535

Dowhile Cond(#W_END <= #W_LENGTH)

#fBase64  := #Current.Substring( #W_START #W_END )
Add_Entry To_List(#imageList)

#W_START := #W_START + 65535
#W_END := #W_END + 65535

If Cond(#W_END > #W_LENGTH)
#W_END := #W_LENGTH
#fBase64 := #current.Substring( #W_START #W_END )
Add_Entry To_List(#imageList)
Leave
Endif

Endwhile
Art

Re: Continuing saving images Lansa mobile

Posted: Thu Jan 18, 2018 7:19 am
by atostaine
Does the #binaryData.FromBase64String return a BLOB? I can use it as a JPG?

I can't seem to get it to save anything correctly either as a BLOB or CLOB.

Thanks, Art
tsupartono wrote: Tue Nov 14, 2017 7:55 am You can still use PRIM_ALPH.

I noticed in the example I provided, the FromBase64String invocation is missing the String parameter name.
The String parameter name does need to be specified.
Please see the corrected code below.

Code: Select all

Define_Com Class(#PRIM_ALPH) Name(#MyBase64String)

#BinaryData.FromBase64String String(#MyBase64String)

Decode from Base64

Posted: Tue Sep 20, 2022 11:49 pm
by Speedlime
Thanks I was looking for a example of this, I can confirm this works well.
Pulling data from Json Response, and decoding it.

DEFINE_COM Class(#PRIM_ALPH) Name(#MyBase64String)

#Reader.SetSourceHttpResponse Httpresponse(#Request.Response)

#Reader.BeginObjectWithPath Path('paperwork')
* Get manifest block of data which is written as Base64
#MyBase64String := #Reader.ReadStringWithName( 'manifest' ).AsNativeString
* Decode Base64 string
#BinaryData.FromBase64String String(#MyBase64String)
#STD_BLOB := #BinaryData.AsFile

#Reader.EndObject