Title: Accessing device camera from within a Genero Mobile application Post by: Richard M. on October 10, 2024, 02:26:40 pm Hi, We need our current mobile app to be able to open the device camera in response to a user request, take a photo and reference it in the database for later upload to the back-end DB. We have not done any significant development work for a while so would appreciate some help on where to look for examples on how to do this. I presume its via a 'frontcall' somehow(?) Bit of a broad question perhaps, but i'm not sure where to start looking.... Thanks Title: Re: Accessing device camera from within a Genero Mobile application Post by: Scott B. on October 10, 2024, 05:10:18 pm Hi Richard:
While I expect others to reply with more examples, I wanted to point you to the BDL documentation topic "Images on mobile devices" at https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_images_dynamic_images.html#c_fgl_images_dynamic_images__mobile_images (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_images_dynamic_images.html#c_fgl_images_dynamic_images__mobile_images) Title: Re: Accessing device camera from within a Genero Mobile application Post by: Richard M. on October 10, 2024, 05:47:23 pm That's great
Thanks Scott Title: Re: Accessing device camera from within a Genero Mobile application Post by: Richard M. on October 17, 2024, 05:42:48 pm Hi,
Thought i was on the right track with this but am getting an error at the 'CALL security.Base64.FromByte' line below, saying 'Forms Statement Error -15701 Invalid Parameter'. Can anyone help plz? Thanks FUNCTION LIB_CHT_GET_PHOTO() #REMPHOTOS CONSTANT l_vm_fn = "mypic.tmp" DEFINE l_md_fn STRING, l_image BYTE, l_photos RECORD LIKE photos.*, b64string STRING --CALL LIB_CHT_TAKE_PHOTO() RETURNING l_filename TRY -- This front call may fail if the front-end is not a mobile device: CALL ui.Interface.frontCall( "mobile", "takePhoto", [], [l_md_fn] ) CATCH MESSAGE "Cannot take photo: ", STATUS, " ", err_get(STATUS) LET l_md_fn = NULL END TRY IF l_md_fn IS NOT NULL THEN CALL fgl_getfile(l_md_fn, l_vm_fn) LOCATE l_image IN FILE l_vm_fn CALL security.Base64.FromByte(l_image) RETURNING b64string INITIALIZE l_photos TO NULL LET l_photos.photo_id = NULL LET l_photos.filename = l_md_fn LET l_photos.photo = b64string LET l_photos.sync = "1" INSERT INTO photos VALUES l_photos.* LET l_photos.photo_id = LIB_SYS_GET_ID("photos") END IF END FUNCTION Title: Re: Accessing device camera from within a Genero Mobile application Post by: Richard M. on October 19, 2024, 11:42:24 pm The below code now works.
-----------------------------; FUNCTION LIB_CHT_GET_PHOTO(l_drop_id) #REMPHOTOS CONSTANT l_vm_fn = "mypic.png" DEFINE l_drop_id INTEGER DEFINE l_md_fn STRING, l_image, l_byte BYTE, l_photos RECORD LIKE photos.*, b64string STRING, l_text TEXT --CALL LIB_CHT_TAKE_PHOTO() RETURNING l_filename TRY -- This front call may fail if the front-end is not a mobile device: CALL ui.Interface.frontCall( "mobile", "takePhoto", [], [l_md_fn] ) CATCH MESSAGE "Cannot take photo: ", STATUS, " ", err_get(STATUS) LET l_md_fn = NULL END TRY IF l_md_fn IS NOT NULL THEN CALL fgl_getfile(l_md_fn, l_vm_fn) CALL security.Base64.LoadBinary(l_vm_fn) RETURNING b64string LOCATE l_text IN MEMORY LET l_text = b64string INITIALIZE l_photos TO NULL LET l_photos.photo_id = NULL LET l_photos.drop_id = l_drop_id LET l_photos.filename = l_md_fn LET l_photos.photo = l_text LET l_photos.sync = "1" INSERT INTO photos VALUES l_photos.* LET l_photos.photo_id = LIB_SYS_GET_ID("photos") END IF END FUNCTION Title: Re: Accessing device camera from within a Genero Mobile application Post by: Richard M. on October 19, 2024, 11:46:09 pm Plus you need to;
IMPORT security Title: Re: Accessing device camera from within a Genero Mobile application Post by: Reuben B. on October 20, 2024, 02:35:14 am Re your error with security.base64.FromByte, note the Important tip in the documentation https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_gws_SecurityBase64_FromByte.html
Title: Re: Accessing device camera from within a Genero Mobile application Post by: Sebastien F. on October 21, 2024, 08:21:54 am Hello Richard,
Can you please provide the context (Genero version, Front-ends type and version, DB servers type and version, OSes type and version, etc) - We can better help if we know the context and such "details". I was wondering why you need to convert the image data to base64. I assume this is to send the images as plain text to the server? About using IMPORT security: While security.Base64.FromByte() needs the BYTE to be located in memory, DISPLAY BY NAME needs the BYTE to be located in a file: https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_images_dynamic_images.html Section "Displaying images contained in BYTE variables" Since Genero BDL 2.51, we have util.Strings methods to encode/decode in base64. https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ext_util_Strings_methods.html Except if you really need other APIs of the "security" module in your mobile app, I would just use the "util" package. How to you plan to upload the photos to the central database? Using RESTful Web Services? What is the SQL CREATE TABLE DDL for the local mobile l_photos table and its equivalent on the server side to store photos? Seb Title: Re: Accessing device camera from within a Genero Mobile application Post by: Sebastien F. on October 21, 2024, 04:28:35 pm Attached a sample using takePhoto / choosePhoto front calls and displaying the photo. If someone has a better way to do this for mobile apps, suggestions are welcome. Seb Title: Re: Accessing device camera from within a Genero Mobile application Post by: Sebastien F. on October 22, 2024, 08:24:00 am Note that when running on mobile, you can directly display the opaque filename returned by the takePhoto or choosePhoto front call. Warning: you must remove UNBUFFERED mode in the main.4gl sample, otherwise the BYTE variable automatic display will take place. Code
But that opaque filename is only valid during the lifetime of the app instance. If you want to store the images in the local database to keep it persistent, you have to store the BYTE data (or the TEXT in base64, if there is any good read for that) Seb Title: Re: Accessing device camera from within a Genero Mobile application Post by: Roland W. on October 22, 2024, 09:05:24 am Sebastien,
are there any substantial differences between the routines of the util.Strings and security.Base64 packages? What's the (dis)advantage of using one of the two packages? I wasn't aware that both packages contain the same routines. Couldn't the documentation of the security.Base64 package point out to use the routines from util.Strings? Apart from that, the parameters are described differently in the two packages. For example, the security.Base64.LoadBinary() (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_gws_SecurityBase64_LoadBinary.html (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_gws_SecurityBase64_LoadBinary.html)) function specifies the parameter “path”, while the util.Strings.base64Encode() (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ext_util_Strings_base64Encode.html (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ext_util_Strings_base64Encode.html)) function is called with the parameter “filename”. With the latter, it is not explicitly pointed out that the filename can also access network resources. Perhaps the documentation of the two packages could be standardized accordingly.. Kind regards Roland Title: Re: Accessing device camera from within a Genero Mobile application Post by: Sebastien F. on October 22, 2024, 10:08:55 am Hello Roland,
Quote are there any substantial differences between the routines of the util.Strings and security.Base64 packages? What's the (dis)advantage of using one of the two packages? There should be no differences regarding pure base64 encoding/decoding. However, as mentioned by Reuben, there is a constraint with security.Base64.FromByte()/ToByte() requiring the BYTE to be located in memory. I see an advantage on using util.Strings because there are less dependencies to other libs, if you need only to do base64 conversions. Here the deps of the security.so library on my Linux box: Code
Versus libfgl.so, where the IMPORT util package is built-in: Code
Quote I wasn't aware that both packages contain the same routines. Couldn't the documentation of the security.Base64 package point out to use the routines from util.Strings? I will talk to the doc team about that, but usually we want to keep things independent. You should be able to find all pages related to base64 support by using the doc search field. Just try with "base64". Quote Apart from that, the parameters are described differently in the two packages. For example, the security.Base64.LoadBinary() (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_gws_SecurityBase64_LoadBinary.html) function specifies the parameter “path”, while the util.Strings.base64Encode() (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ext_util_Strings_base64Encode.html) function is called with the parameter “filename”. With the latter, it is not explicitly pointed out that the filename can also access network resources. Perhaps the documentation of the two packages could be standardized accordingly.. You make a good, point but this is not a doc problem but rather an implementation problem: The signature these methods uses different parameter names You can see this by using code completion in vim, GST or VSCode. Best regards, Seb Title: Re: Accessing device camera from within a Genero Mobile application Post by: Richard M. on October 22, 2024, 06:34:57 pm Hello Richard, Can you please provide the context (Genero version, Front-ends type and version, DB servers type and version, OSes type and version, etc) - We can better help if we know the context and such "details". I was wondering why you need to convert the image data to base64. I assume this is to send the images as plain text to the server? About using IMPORT security: While security.Base64.FromByte() needs the BYTE to be located in memory, DISPLAY BY NAME needs the BYTE to be located in a file: https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_images_dynamic_images.html Section "Displaying images contained in BYTE variables" Since Genero BDL 2.51, we have util.Strings methods to encode/decode in base64. https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ext_util_Strings_methods.html Except if you really need other APIs of the "security" module in your mobile app, I would just use the "util" package. How to you plan to upload the photos to the central database? Using RESTful Web Services? What is the SQL CREATE TABLE DDL for the local mobile l_photos table and its equivalent on the server side to store photos? Seb Thanks Seb, The image is indeed converted to base64 so it can be sent as text via Web Services. I altered my code to use util.Strings.base64Encode and it works fine. One additional issue/question; I want to use the path returned from ui.Interface.frontCall( "mobile", "takePhoto", [], [path] ) to delete the picture held on the Android device after it has been processed. An example of the path returned is 'content://media/external_primary/images/media/457?name=JPEG_GMA_20241022_170235.jpg&ext=jpg' I was hoping to use os.Path.delete() to remove the picture, but the path above is invalid. Any ideas on how to do this? Thanks Title: Re: Accessing device camera from within a Genero Mobile application Post by: Sebastien F. on October 23, 2024, 10:57:02 am Hello Richard,
Regarding os.Path.delete() of a filename returned by takePhoto / choosePhoto: I cannot help I am not expert for GMA/GMI internals. Seb |