HOWTO: Save image files in TinyDB. Extension Base64.

4,070 views
Skip to first unread message

Juan Antonio

unread,
Aug 13, 2019, 11:47:22 AM8/13/19
to mitappinv...@googlegroups.com

(edited)

Hello friends, 


- It is an extension to convert files <--> String Base 64.

- Extension: com.KIO4_Base64.aix

- In this example: we can Save images, sounds files,... in the TinyDB.

extension_base6420.png

extension_base64_1i.png




- Using the block: FileToString, we can convert files to String Base64.

- We Store that String in the TinyDB with a tag. Different tag for different file.

- We can Get that String from the TinyDB, decode it and save it in an auxiliary file in the SdCard: /mnt/sdcard/aux_file

- Note that it is not necessary set extension file aux_file. This file is common to any conversion.

 - We can set this auxiliary file in an Image.Picture or in a Player.Source using the address: file:///mnt/sdcard/aux_file
 
- If file is in asset: fileName: //myphoto.jpg

- If file is in sdcard: fileName: /myphoto.jpg
 
 We cann't upload extensions.aix files to this forum, so I link to:
 
 
 - Also through this extension we can copy the asset files in the SdCard.
 
 Regards.
 
 Juan Antonio Villalpando.

TimAI2

unread,
Aug 13, 2019, 1:37:16 PM8/13/19
to MIT App Inventor Forum
Great work Juan !

Will this convert ANY file to base64 or just image and audio files ?
Is you base64 conversion compatible with Google Drive ?

BodyMindPower

unread,
Aug 14, 2019, 7:39:26 AM8/14/19
to MIT App Inventor Forum
Hi Juan, great!

There is no need to ask for READ_EXTERNAL_STORAGE permission, because WRITE_EXTERNAL_STORAGE implicitly grants READ permission.




Anke

Juan Antonio

unread,
Aug 14, 2019, 8:37:25 AM8/14/19
to MIT App Inventor Forum
Thanks Anke, that's right.

Juan Antonio

unread,
Aug 20, 2019, 9:12:51 AM8/20/19
to MIT App Inventor Forum
Experience with large files in TinyBD.

- In our mobile we create the folder: /mnt/sdcard/fotos_grandes

- And in it we load large .jpg files, for example these: 

extension_base64_3.png

- When click in btn_StoreValue, all files will be saved in the TinyDB as String. 


- By continuously pressing btn_GetValue, the images stored in the TinyDB in the image component will be displayed. 


extension_base64_4.png

extension_base64_2i.png


- Source .aia: 

http://kio4.com/appinventor/277i_extension_imagen_string.htm


- About size TinyDB: https://groups.google.com/forum/#!msg/mitappinventortest/AX1gPrAcuvY/2PWHn_NxrrsJ



ABG

unread,
Aug 22, 2019, 3:41:59 PM8/22/19
to MIT App Inventor Forum
(added to TinyDB section of FAQ)
ABG

Juan Antonio

unread,
Aug 24, 2019, 5:28:49 PM8/24/19
to MIT App Inventor Forum
- Thanks Abraham.

- Download a large image file (5 MB) from Internet and Store in TinyDB.

1.- Create directory /auxiliary (in /mnt/sdcard/auxiliary)

2.- Download a large image file (5 MB) from Internet with Web component in auxiliary/mydowloadfile.jpg.

3.- With block FileToString, convert this File To String.

4.- Store this String in TinyDB with tag: my_string

----- Now recover -----------

5.- Get String from TinyDB with tag: my_string

and convert this String To File with block StringToFile and save in /auxiliary/mynewfile.jpg

6.- Show in Picture file:///mnt/sdcard/auxiliary/mynewfile.jpg

7.- Delete directory /auxiliary.

extension_base64_6.png

extension_base64_7.png


- Image to download: https://sample-videos.com/img/Sample-jpg-image-5mb.jpg


Site to download samples images:

https://sample-videos.com/download-sample-jpg-image.php

Site to download samples videos:

https://sample-videos.com/


You can download file .aia from: http://kio4.com/appinventor/277i_extension_imagen_string.htm#3


Regards.

http://kio4.com/appinventor/277_extension_imagen_string.htm




Reply all
Reply to author
Forward
0 new messages