Upload files to Google Drive that are not in assets (file path issue?) [Resolved]

I am following along with this tutorial here:
Upload Any File To Google Drive with AI2 by TIMAI2 (Thanks Tim!)

...and have got it working. I am able to upload an image from AI2 media assets to my google drive. I have successfully created the web app script, etc. Great, awesome, it works, it's amazing!

However, I am now trying to adapt it to work with some other file that does not already exist in assets (an image taken with the camera, for example).

Using TaifunFile, I am able to get a list of files and find an image from a specific directory on my phone, lets say:
file:///sdcard/DCIM/Camera/IMG_20200609_205137306.jpg

I know this is a valid file path because I can use this path to display the photo on my app, using:
set image1.picture to file:///sdcard/DCIM/Camera/IMG_20200609_205137306.jpg

However, I have not figured out how to format this path/file to get it to upload to the drive like a media asset file. In the image below, only "troll.jpg" will upload (troll.jpg is preloaded into the media assets of the app).

The others give the following error:

java.io.FileNotFoundException: /storage/emulated/0/AppInventor/assets/sdcard/DCIM/Camera/IMG_20200609_205137306.jpg (No such file or directory)

which shows how the file path is getting mangled. The original tutorial indicates there is a way to upload files from the virtual SD card. Is this different than the phone's SD card? Is there a way to upload a file from phone storage and what is the correct path/file formatting for KIO4_Base641 fileExtension?

Just started using AI2. Thank you for any pointers you can provide!

Best,
Blake

a valid path to the internal sdcard looks like
file:///storage/emulated/0/DCIM/Camera/IMG_20200609_205137306.jpg
a valid path to an external movable sdcard looks like
file:///storage/02C3-E96C/DCIM/Camera/IMG_20200609_205137306.jpg

to get the mime type of a file on internal or external sdcard, you have to remove the 2 leading slashes, assuming that extension by @Juan_Antonio uses the same logic as the file component...


Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

2 Likes

Thank you for the help. This is what finally worked:

DCIM/Camera/IMG_20200609_205137306.jpg as file path, combined with one slash, per the instructions on Juan Antonio’s own page:
http://kio4.com/appinventor/277i_extension_imagen_string.htm

DCIM is a folder sitting in the root directory of my memory card. I verified this in the Android settings/storage, selecting SD card, then clicking explore.

Below is what the working blocks look like:

(This is for images stored in a folder on the external SD card of my Samsung XT1609 tester phone, running Android 7.1.1)

it looks like you are talking about your internal sdcard...
and now you are using a relative path, which makes sense...

Taifun

This is a removable card from inside the phone case, but it is not the built-in storage. See the screenshots.

What is an “external sdcard” if this removable one is considered internal?

Best,
Blake

Obviously you have selected the external (removable, micro) SDcard as the storage location in the camera settings of your device. I'm pretty sure that the path you declared (/DCIM/Camera/...) will not work on all (other) devices. @Taifun has already explained that.

See here:

@Anke Thank you for the internal/external storage links.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.