I need to copy few files with known names from ASD to user selected external directory. I'm using SAF. But saf.CopyDocument gives an error asking to obtain permission also for the file in ASD.
I'll will be very thankful for the help.
I'm using Saf.OpenDocumentTree. The user is choosing the directory and then I'm trying to copy the first file using saf.CopyDocument in SAF.GotUri (see below simplified block) but in the response in saf.GotCopyResult I'm seeing an error:
Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fdata%2Fappinventor.ai_aagorine.MyName%2Ffiles%2F00007/document/primary%3AAndroid%2Fdata%2Fappinventor.ai_aagorine.MyName%2Ffiles%2F00007%2F1110.mp4 from pid=15035, uid=10552 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
Since I tested in companion so I have prefixed // before file name to get absolute file path but you have to provide complete path there.
The issue here is that you'll have to create documents yourself. I thought of implementing it as fallback case of CopyDocument but somehow it slipped out.
Thanks Sunny. It's a workaround and I'll try it (hoping readasbytearray is able to allocate memory for up to 5GB files that were copied to ASD by saf.CopyToASD).
But if you have the time, I'll gladly sponsor the CopyDocument upgrade or/and the new saf.CopyFromASD which will not need memory allocation to read the whole file but will read it in chunks
Hi Sunny, unfortunately ReadAsByteArray is unable to read huge files from ASD giving memory allocation error (see attached screenshot for a file of about 60MB - for 1GB file it simply close the app).
I implement your workaround and it able to copy small files in the subdirectory created with SAF inside the directory selected by the user, but not big files. And it seems strange because I remember that I was testing your new version of ReadAsByteArray with 500mb files before I began to use CopyToASD (could you please check - i'm using v.1.2 date built: 2023-07-03 and CopyToASD was able to copy also 5+GB files)
I guess the only solution to avoid completely the memory allocation problem is to implement a new CopyFromAsd block with read and write of chunks like you have done it in CopyTOAsd (if it's feasible for you)
Chris, these are just video files shot by the smartphone itself.
p.s Sunny has already implemented new blocks and you will see it in the new version of SAF