breautek commented on issue #367:
URL: 
https://github.com/apache/cordova-plugin-file-transfer/issues/367#issuecomment-1701270786

   It sounds like you're experiencing scoped storage rules, which is effective 
since API 29. I wrote a blip in a 
[PR](https://github.com/apache/cordova-plugin-file/pull/593) for the file 
plugin but the same would apply here.
   
   Basically scoped storage applies to all external storage  partitions 
(`/storage/emulated/0/` is considered an external storage partition, which is 
used to emulate external storage when a physical medium is not available).
   
   With scoped storage, applications do not require permission to read or write 
files, however it can *only* read and write files that the application itself 
has written to. So for example, if another app (Say the chrome browser) 
downloads a file and stores it at: 
`/storage/emulated/0/Download/MyApp/BYG/REIA_Check_List.doc`, that file will 
not be read or writeable  by your app since the file is not owned by your app.
   
   Listing directories will not show files that your app doesn't have access 
to. However attempting to write to a filename that already exists will be 
blocked.
   
   There is limited capability of reading files owned by other apps with 
`READ_EXTERNAL_STORAGE` permission on pre-API 33 devices, and 
`READ_MEDIA_AUDIO`, `READ_MEDIA_VIDEO`, and `READ_MEDIA_IMAGES` for API 33+ 
devices. If you're observant you'll notice that there are only permissions for 
multimedia assets, but not nothing for document files. This is because scoped 
storage only allows reading media files. So reading your .doc file is not 
possible via a file API. Additionally, there are no write permissions for 
writing to files owned by other apps. You cannot modify a file owned by another 
app via the file api.
   
   The file transfer plugin uses the file plugin behind the scenes, which 
naturally uses the file apis.
   
   **So how do work with non-media files?**
   
   Well the native way is to use a non-file API, and use something called a 
MediaStore. Apache doesn't have a plugin that interfaces with this MediaStore 
outside of context specific plugins (like the camera plugin which deals with 
images/video). But there are third-party plugins available that interfaces with 
the media store with a generic API: 
https://www.npmjs.com/search?q=ecosystem%3Acordova%20storage%20access%20framework
   
   If placing these files in external storage is a requirement, then you'll 
probably need to use the file transfer plugin to download into your internal 
cache directory (`cordova.file.cacheDirectory`), then use a media store plugin 
to transfer from the internal cache directory to media store.
   
   Lastly if you support API 29, then using MediaStore APIs is a 
**requirement** because Android lacks a filesystem API into scoped storage, 
which was only introduced in API 30. So accessing any external storage 
mechanism on API 29 is blocked.
   
   If you think any of this sounds bizarre, then you're not alone. You can read 
learn more about scoped storage in the [android 
docs](https://source.android.com/docs/core/storage/scoped)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to