Continuing saving images Lansa mobile
Continuing saving images Lansa mobile
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
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
Art Tostaine
Re: Continuing saving images Lansa mobile
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
",["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]
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
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]
Art Tostaine
-
tsupartono
Re: Continuing saving images Lansa mobile
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.
You can find the documentation for XPRIM_Binary here:
http://docs.lansa.com/14/en/lansa015/in ... 0_0010.htm
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
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.
Re: Continuing saving images Lansa mobile
Thanks. USA tech support didn't know about this. I'll install it and check it out.
Art
Art
Art Tostaine
Re: Continuing saving images Lansa mobile
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
I need to scan barcodes also so I'm using LANSA Mobile. Is there a way to scan barcodes without it?
Thanks, Art
Thanks, Art
Art Tostaine
Re: Continuing saving images Lansa mobile
How do I define the base64string? Previously I was using a PRIM_ALPH field to hold the base64 string.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.
You can find the documentation for XPRIM_Binary here:Code: Select all
Define_Com Class(#XPRIM_Binary) Name(#BinaryData) #BinaryData.FromBase64String(#MyBase64String) #STD_BLOB := #BinaryData.AsFile
http://docs.lansa.com/14/en/lansa015/in ... 0_0010.htm
Thank you.
Art Tostaine
-
tsupartono
Re: Continuing saving images Lansa mobile
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.
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
Thank you. I was using alt-space and searching the docs to try and figure out what was wrong. Another few hours maybe. 
Art Tostaine
-
VLNinja70
Re: Continuing saving images Lansa mobile
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
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
Re: Continuing saving images Lansa mobile
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.
Art
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 Tostaine
Re: Continuing saving images Lansa mobile
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
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)
Art Tostaine
Decode from Base64
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
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