File extension copy to external sd is possible?

1007 views
Skip to first unread message

Luisjfe

unread,
Mar 23, 2016, 6:07:08 AM3/23/16
to MIT App Inventor Forum

Hi Taifun,

After reading all the documentation I found about writting to an external sd card from App Inventor, I concluded it was not possible neither with the file component nor with the canvas.saveas method. Then I reached to your File Extension page and I thought that it was a workaround for this issue.

I've been testing your File extension for App Inventor and I can't manage to copy a file from an internal sd location to an external sd location. The from file is provided by the camera, I mean it's any picture I've just taken with the camera. And the to file has to be located on a given external place. In the Pura Vida File Extension page you say:  "If a fileName starts with file:/// you can specify a complete path to the file". But every time I try to copy to "file:///mnt/ext_card/Pictures/picturen.jpg" I get an error about a bad name for the ToFileName. The folder Pictures already exists and ext_card is the actual name of my external sdcard.

Am I doing something wrong? Or it's just that the extension is not able to write to an external sd card.

I enclose a file with the blocks I'm using.

Thank you in advance,
Luis.
Copy.png

Taifun

unread,
Mar 23, 2016, 10:12:30 AM3/23/16
to MIT App Inventor Forum
see Q1 here https://puravidaapps.com/file.php#q
can you provide a screenshot which shows, that file:///mnt/ext_card is the correct path to your external sdcard?
Taifun

Luisjfe

unread,
Mar 24, 2016, 4:13:53 AM3/24/16
to MIT App Inventor Forum
Sure. Here you are.

I'm sending you two ways I can found my folder in the file system tree of my device. Tried both, no result. By the way I've tried it on a Sony Xperia E1 (the one of the example) and a Samsung galaxy. Of course it was a diferent path (but still a well known path) on each one but I could not copy anyway.

Thanks for your time.

Screenshot_2016-03-23-23-12-33.png
Screenshot_2016-03-23-23-14-06.png

Taifun

unread,
Mar 24, 2016, 4:48:59 PM3/24/16
to MIT App Inventor Forum
did you try file:///storage/sdcard1/... ?
Taifun

Luisjfe

unread,
Mar 24, 2016, 5:54:36 PM3/24/16
to MIT App Inventor Forum
Hi Taifun,

Yes I did. But I got the same error message: probably ToFileName is an invalid name?

Any clue?

Taifun

unread,
Mar 24, 2016, 6:01:28 PM3/24/16
to mitappinv...@googlegroups.com
you might want to provide a screenshot of your relevant blocks including Do it result of the file name and a screenshot of the error message
Taifun

Luisjfe

unread,
Mar 25, 2016, 5:36:08 AM3/25/16
to MIT App Inventor Forum
The blocks I use for this are in my first post. Nothing's changed. The logic is pretty simple.

I call Camera to take a picture.
When the picture is taken, wherever it is stored, the path is in the image local I use as the FromFileName.
Then I copy it to ToFileName using your extension. The ToFileName is: "file:///mnt/ext_card/Pictures//Foto + asecuencialnumber + .jpg" or "file:///storage/sdcard1/Pictures/Foto + asecuencialnumber + .jpg" (I've tried both)
Once I have the destination file on the final folder, I delete the original file from the internal storage.
I add the new picture reference in a TinyDb and in a list to use it later.

The Do it result of the file name can't be shown for it doesn't exist. As it return an error in the copy process it was never created, so there is nothing to show.

In the attached file you can see the error I get.

Thanks again.

Screenshot_2016-03-25-10-25-58.png

Taifun

unread,
Mar 25, 2016, 10:30:46 AM3/25/16
to mitappinv...@googlegroups.com
I now prepared a new version 3a of the file extension, which provides a better error message in this case
EDIT: Please download the new version from here https://downloads.sourceforge.net/project/puravidaapps/com.puravidaapps.TaifunFile.aix

please try again using this version
after replacing the version of the file extension you have to restart the companion app

The ToFileName is: "file:///mnt/ext_card/Pictures//Foto + asecuencialnumber + .jpg" or "file:///storage/sdcard1/Pictures/Foto + asecuencialnumber + .jpg" (I've tried both)
you should try with file:///storage/sdcard1/...
so what is the value of asecuencialnumber ?

btw you always can use Do it to debug your blocks, see also tip 4

especially it would be interesting, how the ToFileName looks like EXACTLY
probably there is a space inside the filename?

you might want to provide a screenshot of your relevant blocks including Do it result of the file name and a new screenshot of the error message

Taifun

Luisjfe

unread,
Mar 25, 2016, 12:22:05 PM3/25/16
to MIT App Inventor Forum
Ok, Taifun.
I'm going to put all this together and as soon as I have something I'll let you know.
Thank you for the new version of the extension and thanks for all your effort too.
Regards, Luis.

Luisjfe

unread,
Mar 29, 2016, 10:36:58 AM3/29/16
to MIT App Inventor Forum
Hi, Taifun,

Here I'm back again.

I tried the app with your new version of the File Extension and this is what came out:

When conected to AI by USB I can't operate the device because AI causes an error and the screen on the device goes white. (You can see this error in the attached file BlocksError.png).

Anyway the Do It result of the block you are asking me for is: file:///storage/sdcard1/Pictures/Foto5.jpg. It seems that there are no spaces in between. (Attached file BlocksDoIt.png)

When I built the apk and installed this on the device, I got an error reporting: /storage/sdcard1/Pictures/Foto5.jpg: open failed: EACCES (Permission denied)  (Attached file Screenshot_2016-03-29-14-12-24.png)

In the Attached file Blocks.png I'm sending you the clean image of the blocks I'm using for this try. Here, asecuencialnumber is the length of the list where I'm storing the picture, just to give a different new name to the picture each time I get one.

Hope you can obtain useful information with all this stuff so you can help me.

Thanks, Luis.


Blocks.png
BlocksDoIt.png
BlocksError.png
Screenshot_2016-03-29-14-12-24.png

Taifun

unread,
Mar 30, 2016, 5:36:45 PM3/30/16
to MIT App Inventor Forum
When conected to AI by USB I can't operate the device because AI causes an error and the screen on the device goes white. (You can see this error in the attached file BlocksError.png).

as already said, you have to reconnect the companion app after using the new version of the extension

I will investigate about the permission error
which device/Android version are you using for your tests?
Taifun

Luisjfe

unread,
Mar 31, 2016, 4:40:24 AM3/31/16
to mitappinv...@googlegroups.com
What do you mean with "reconnect the companion app"? After updating the version of the extension I have reconnected through the main menu Connect/Reset Connection and Connect/USB options. Even closed and restarted companion with AiStarter on my PC and stopped companion on my device before retrying. Isn't that enough?

For your information, AI returns the error when I use your component in the project while connected via USB. EDIT: Or via WI-FI connection. It doesn't matter whether I use any block or not. Just including the extension in the app causes this runtime error. Anyway this is not my biggest trouble for it seems to be a debug mode issue.

I'm using a Sony Xperia E1 device running Android 4.4.2 compilation number 20.1.A.2.19

Thank you.
Luis.

Taifun

unread,
Mar 31, 2016, 10:54:11 AM3/31/16
to MIT App Inventor Forum
What do you mean with "reconnect the companion app"? After updating the version of the extension I have reconnected through the main menu Connect/Reset Connection and Connect/USBoptions. Even closed and restarted companion with AiStarter on my PC and stopped companion on my device before retrying. Isn't that enough?

after importing the new version of the extension you then have to restart the companion app, else the old version of the extension is still there

I'm using a Sony Xperia E1 device running Android 4.4.2 compilation number 20.1.A.2.19

ok, so it's not an Android 6 permission issue
do you have your device still connected via USB? 

Taifun

Luisjfe

unread,
Apr 1, 2016, 3:43:02 AM4/1/16
to MIT App Inventor Forum

after importing the new version of the extension you then have to restart the companion app, else the old version of the extension is still there

What you say is, in other words, what I did but AI is still reporting the debug mode runtime error. This error happens whenever the device is connected to the PC via USB or WI-FI and I include a reference to the file extension component in the app. For now I'm bypassing this by compiling and installing the apk directly on my device.

And this leads us to the main question: the EACCESS error when copying to the external SD card. When I get this error the device is not connected to the computer. The app is running on the device. btw, I've checked that the folder I want to copy to has read/write permissions.

On the other hand, I'm sure that I'm using the latest version of your file extension because other way I couldn't get the "EACCES (Permission denied)" error message I reported you. Remember that when using the older version the message was "Sorry, there was an error, probably ToFileName is not a valid filename?"

Thank you.
Luis.

Taifun

unread,
Apr 1, 2016, 11:31:28 AM4/1/16
to mitappinv...@googlegroups.com
What you say is, in other words, what I did but AI is still reporting the debug mode runtime error. This error happens whenever the device is connected to the PC via USB or WI-FI and I include a reference to the file extension component in the app. For now I'm bypassing this by compiling and installing the apk directly on my device.

try to reinstall the companion app, then try again
you now also can download version 3b of the file component, which fixes another issue, see also here https://groups.google.com/d/msg/mitappinventortest/ctlUDplk-wE/WnFe-T0vEQAJ

concerning your "permission denied" issue, unfortunately I do not have a device, which has an external sdcard, so I'm not able to test this
for some people the copy method worked fine for external sdcards, for you unfortunately it seems to not work

therefore I now have to say, using the file extension together with an external sdcard is an "experimental feature" for now
sorry for not being able to help in this case

Taifun

Luisjfe

unread,
Apr 1, 2016, 2:03:43 PM4/1/16
to MIT App Inventor Forum
Ok, I'll give your 3b version a try and will reinstall companion app.

I'm very sorry to hear that you can't test this issue on a device with an external SD card for I think it's not just a problem with my device but a general one, because I've tried several devices and it didn't work on none of them.

Anyway, I recognize a good job when I see it and yours is, for sure. You are on the way.

Hope you can solve this in a not very long term. Maybe next version?

Thank you for your help and for all what you're doing for this community.
Luis.

Taifun

unread,
May 3, 2016, 3:13:39 PM5/3/16
to MIT App Inventor Forum
as MxyzptlkHavok found out here https://groups.google.com/d/msg/mitappinventortest/UASr2oiclfI/bVeTalsdAgAJan app can only write to its own directory on the external sdcard, but can't create its own directory!
Taifun

Luisjfe

unread,
May 10, 2016, 6:18:34 AM5/10/16
to MIT App Inventor Forum
Hi Taifun

Thanks for the info. I think it doesn't solve my issue but any explanation about the android file sistem and appinventor is welcome.
Reply all
Reply to author
Forward
0 new messages