Save image, sound, clip (video), canvas in TinyDB. Extension Base 64. Download file from the web and convert it to string

3.- Video (clip) to TinyDB by Base 64.

Base64_Direct_TinyDB_Camcorder.aia (36.7 KB)

1.- Take video.
2.- Save video to file then to String.
3.- Store string in TinyDB.
4.- Getvalue string from TinyDB
5.- String to file in ASD
6.- Show video, deleting any files.

clip is a uri:
clip: content://media/external/video/media/265218

using the extension we convert it to path:
clipPath: /storage/emulated/0/DCIM/Camera/VID_20210902_104632.mp4

3 Likes

4.- Canvas to TinyDB by Base 64.

Base64_Direct_TinyDB_Canvas_2.aia (37.2 KB)

1.- Save Canvas to file to String.
2.- Store string in TinyDB.
3.- Getvalue string from TinyDB.
4.- String to file in ASD.
5.- Show Canvas image, deleting any files.

2 Likes

5.- Summary:

Variable image in Camera is:
file:///storage/emulated/0/My Documents/Pictures/app_inventor_16344444.jpg [MIT Companion]
file:///storage/emulated/0/Pictures/app_inventor_16344444.jpg [Android <10]
file:///storage/emulated/0/Android/data/'namepackage'/files/Pictures/app_inventor_16344444.jpg [Android >=10]

Variable sound in SoundRecorder is:
/storage/emulated/0/sound_16344444.3gp [Android <10]
/storage/emulated/0/Android/data/'namepackage'/files/sound_16344444.3gp [Android >=10]

Variable clip in Camcorder is:
content://media/external/video/media/265218 [it is a uri]
/storage/emulated/0/DCIM/Camera/VID_20210902_104632.mp4 [uri to path with an extension]

Source in Image, Player and VideoPlayer.
if start with /mnt, is necessary file://

file:///mnt/sdcard/gato.png
file:///mnt/sdcard/beep.mp3

if start with /storage, isn't necessary file://

/storage/emulated/0/gato.png
/storage/emulated/0/beep.mp3

Asset MIT Companion Android < 10
/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/AppInventor/assets/

Asset MIT Companion Android >= 10
/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/assets/

Asset Emulator
/mnt/sdcard/Android/data/edu.mit.appinventor.aicompanion3/files/AppInventor/assets/

Asset installed.
android_asset

Asset in old versions of MIT Companion (now deprecated)
/storage/emulated/0/AppInventor/assets

2 Likes

6.- Download an image from the web and convert it to a Base 64 string.

Base64_Direct_TinyDB_WebFile.aia (117.8 KB)

1.- Download an image file from the web and save it in ASD/temp/nameFile.png
2.- Show image file in Image1 component.
3.- In event gets string of ASD/temp/nameFile.png and convert ASD/nameFile_mirror.png
4.- Show imageFile_mirror.png in Image2 component.

Source image:
https://www.pexels.com/es-es/

2 Likes

7.- Blocks: ImageToBase64, Base64ToImage, CanvasToBase64 and TakePictureToBase64.

These blocks were ideas from @TIMAI2 :

  • Convert an Image component to string Base 64. [This code was made by @Kumaraswamy]
    base64_28a

  • Set picture in Image component by string Base 64.
    base64_23b

  • Convert image in Canvas component to string Base 64. [This code was made by @Kumaraswamy]
    base64_28c

  • Take picture with Camera component and convert image to string Base 64 [This code was made by @TIMAI2]
    base64_28d

Base64_Image_Canvas.aia (488.3 KB)

Related topic:

3 Likes

these are some great examples...
can you please also create a thread in the #extensions category to present the extension including a link to download the extension?
Thank you

Taifun

2 Likes

Original KIO4_Base64 Extension is updated, you can get it here:

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

should be the same link as on your site

1 Like

Why? What have I forgotten and not added in the program code? Please Help.
Runtime Error Unsupported path /storage/emulated/0/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/uc

1 Like

If you want to save to your ASD, do it like this:

the block expects a filename in address, I do not believe this will handle google drive links.
@Juan_Antonio may know different!

1 Like

2 Likes

Thanks, but not support google drive. do you have solution for google drive files. :thinking: :pray:

1 Like

:pray: :sob:
I think that.

1 Like

Use the web component (once it is fixed!), that way you can give it a filename when you download.

2 Likes

Not working!
I know exist solution with google app script but looking for easy way.

1 Like

No google apps script required if file set to anyone with the link

image

3 Likes

So why was a 120kb png file on google drive redused to 2kb file in smartphone that can't be shown? Instead of displaying a filename, how do we display the picture? because the file is just 2 kb.

1 Like

That is not my experience.

Show your blocks and a text of your link so that I can test for you

3 Likes

Set an Image component

Image1.Picture = fileName

3 Likes

Yes that working. Sorry.