Continuing saving images Lansa mobile

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
atostaine
Posts: 131
Joined: Wed Jan 20, 2016 7:38 am

Continuing saving images Lansa mobile

Post by atostaine » Fri Oct 20, 2017 5:06 am

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

atostaine
Posts: 131
Joined: Wed Jan 20, 2016 7:38 am

Re: Continuing saving images Lansa mobile

Post by atostaine » Tue Oct 24, 2017 1:34 pm

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]

tsupartono
Posts: 31
Joined: Wed Jan 25, 2017 11:12 am

Re: Continuing saving images Lansa mobile

Post by tsupartono » 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 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
Last edited by tsupartono on Tue Nov 14, 2017 8:04 am, edited 1 time in total.

atostaine
Posts: 131
Joined: Wed Jan 20, 2016 7:38 am

Re: Continuing saving images Lansa mobile

Post by atostaine » Wed Oct 25, 2017 12:07 am

Thanks. USA tech support didn't know about this. I'll install it and check it out.

Art

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

Re: Continuing saving images Lansa mobile

Post by lawingo » Tue Nov 07, 2017 5:55 am

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




atostaine
Posts: 131
Joined: Wed Jan 20, 2016 7:38 am

Re: Continuing saving images Lansa mobile

Post by atostaine » Fri Nov 10, 2017 5:29 am

I need to scan barcodes also so I'm using LANSA Mobile. Is there a way to scan barcodes without it?

Thanks, Art

atostaine
Posts: 131
Joined: Wed Jan 20, 2016 7:38 am

Re: Continuing saving images Lansa mobile

Post by atostaine » Tue Nov 14, 2017 7:09 am

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.

tsupartono
Posts: 31
Joined: Wed Jan 25, 2017 11:12 am

Re: Continuing saving images Lansa mobile

Post by tsupartono » 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)

atostaine
Posts: 131
Joined: Wed Jan 20, 2016 7:38 am

Re: Continuing saving images Lansa mobile

Post by atostaine » Tue Nov 14, 2017 9:22 am

Thank you. I was using alt-space and searching the docs to try and figure out what was wrong. Another few hours maybe. :D

Post Reply