How do copy few files from ASD to the external directory selected by user using SAF

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 uri content:// from pid=15035, uid=10552 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs

Take a look at Sunny's new extension:

You can use file uri instead of content uri.

Thank you Sunny. I've tried already file Uri but it was also the error:

Unknown authority

Thank you Chris, this is a very interesting extension for other my projects and I've taken it.

I was thinking that if your files in the ASD were in a sub-folder, you could move that folder to an external folder.

Actually I need not to move but to copy the folder in ASD to USB stick as a backup. The folder in ASD is huge (up to 100GB of video files)

You can copy files manually in this way.

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.

How did those files get into the ASD?

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

1 Like

From different places using saf.CopyToASD

Those chunks would be in allocated memory :upside_down_face:

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)

1 Like

Alexandre - why are you handling such huge files in this way? This is Desktop/Laptop territory.

What different places? Why different places? Are you downloading these files from the internet? We need to know exactly what is going on.

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


So they should all be in the same place......

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