Files Acces with file component

Hi, I definitely have some difficulties to understand where to place a Csv file in order te read it after from the APP.
I red a very similar post :
' Reading Files from Internal Storage'
But at the end it doesn't work me. :grimacing:
Here is my goal : Copy a CSV files from my PC to My mobile with USB connexion, then open the Csv Files from the App with file component, read the data and write them to a firebase database with Firebase compent.
To make it simple, i built a new project with only this block :
image
I fixed the FileComponent to Share
image
I've copied a test file (ventes_syn2.csv) to the mobile
image
When I launch the App trough AICompanion, the app exit abruptly ! and the connexion is closed.
Then I tried to upload the files
image
But it the files is placed in th app directory


And it doesn't work anyway.
Could somebody can help me ?
Thks

Make sure the 'DefaultScope' property of your File component is set to 'Asset'.

See this screenshot for reference.

1 Like

Hi Gordon, if i set Defautlscope property to Asset, i got the message Error 2101, the file /download/ventes_syn2.csv could not be found... and i think it"s normal, Assets will look for the file in the app directory and mine is in the share directory in download subdirectory.

Hi, a strange thing to add, i tried to write instead to read with this block :
image
And it's run correctly, but it write 'essai' in the file in the share Download directory, but it has erased all the data of the csv file ?!
Loïc

That's strange... it is right in your asset.

But:

Is this your correct file name with the correct capitalization?

1 Like

Maybe just try Ventes_syn2.csv would do it? Or invite a file expert to this topic.

1 Like

Hi Gordon, the capitalization is correct in the block and on the storage. I've just made a mistake when i copied the error message (i've used lowercase letter)

Hi, For the file expert how to find and to invite him/her ?

OK, I know now.

1 Like

Hi Gordon, for your info, i used another Defautscope : 'App', place the files in the directory: "PC\Redmi 9C NFC\Espace de stockage interne partagé\Android\data\edu.mit.appinventor.aicompanion3\files"
And the MIT App find now the files.
I still don"t understand what is going on, it's not where i want, but it's run, so... i will do with
Mny Thks anyway

Me too, I read the documentation and don't understand what the problem is.

  • App: Files will be read from and written to app-specific storage on Android 2.2 and higher. On earlier versions of Android, files will be written to legacy storage.
  • Asset: Files will be read from the app assets. It is an error to attempt to write to app assets as they are contained in read-only storage.
  • Cache: Files will be read from and written to the app’s cache directory. Cache is useful for temporary files that can be recreated as it allows the user to clear temporary files to get back storage space.
  • Legacy: Files will be read from and written to the file system using the App Inventor rules prior to release nb187. That is, file names starting with a single / will be read from and written to the root of the external storage directory, e.g., /sdcard/ . Legacy functionality will not work on Android 11 or later.
  • Private: Files will be read from and written to the app’s private directory. Use this scope to store information that shouldn’t be visible to other applications, such as file management apps.
  • Shared: Files will be read from and written to the device’s shared media directories, such as Pictures .

From the App Inventor documentation for File.

1 Like

It is not possible to read a text file (non-media file) from the external storage (at least not on Android 11), that is not created by the app itself. To be able to read it from the shared storage / folders (/Download or /Documents) you need to save the text file there.

See also here:

1 Like

Hi Anke, sorry i've replied to you in the wrong section. :expressionless:

theoretically it would be possible using the Storage Access Framework...
however up to now we did not get any feedback from @ewpatton, if this feature is on the to do list of the MIT App Inventor team... this is a friendly reminder, so that this topic does not get forgotten...
see also

Taifun


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

Yes, you're right, and my scoped storage overview confirms that.

yes... good job!
I was using your overview as a reference guide... :partying_face:
Taifun

1 Like

I don't know that the team has the bandwidth to implement such a feature right now, but I've filed it as a feature request on GitHub so potential open source contributors can take it on as a project.

3 Likes

thank you
this is very much appreciated!
Taifun

1 Like