I'm struggling with as strange FileSystem.copyAsync behaviour. In RelocatingOption, 'from' is a media file (mp3) with SAF format and 'to' is supposed to be a same name file in FileSystem.documentDirectory.
The unexpected behaviour is that the file has been copied as a directory and not as a file.
Below my code with console.log output that shows 'from' and 'to' info:
result = {"mimeType": "audio/mpeg", "name": "Ho messo via.mp3", "size": 4826349, "type": "success", "uri": "content://com.android.externalstorage.documents/document/primary%3AMusic%2FHo%20messo%20via.mp3"}
`const fileName = result.name;
const destinationFile = `${FileSystem.documentDirectory}${fileName}`;
console.log(`AddSongsScreen:handleNewSong - from: ${result.uri} - to: ${destinationFile}`);
try {
const info = await FileSystem.getInfoAsync(result.uri);
console.log(`AddSongsScreen:handleNewSong - from info: ${JSON.stringify(info)}`);
const out = await FileSystem.copyAsync({
from: result.uri,
to: destinationFile});
console.log(`AddSongsScreen:handleNewSong - to info: ${JSON.stringify(await FileSystem.getInfoAsync(destinationFile))}\`);
} catch(e) {
console.log('AddSongsScreen:handleNewSong - copy error: ',e);
Alert.alert('Error', 'Unable to copy file in document Directory');
return;
}`
And this is the console.log output:
AddSongsScreen:handleNewSong - from: content://com.android.externalstorage.documents/document/primary%3AMusic%2FHo%20messo%20via.mp3 - to: file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540marfing%252Fsimplestage/Ho messo via.mp3 AddSongsScreen:handleNewSong - from info: {"size":4826349,"uri":"content://com.android.externalstorage.documents/document/primary%3AMusic%2FHo%20messo%20via.mp3","isDirectory":false,"exists":true}
As you can see the from file is not a directory
AddSongsScreen:handleNewSong - to info: {"modificationTime":1674123563,"size":4826349,"uri":"file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540marfing%252Fsimplestage/Ho%20messo%20via.mp3","isDirectory":true,"exists":true}
as you can see the getInfoAsync of the destination (to) file (after copyAsync) shows that it has been saved as a directory!!
Obviously trying to open it with expo-av I got a: cannot find audio file: Error: com.google.android.exoplayer2.upstream.z$b: java.io.FileNotFoundException: /data/user/0/host.exp.exponent/files/ExperienceData/%40marfing%2Fsimplestage/Ho messo via.mp3: open failed: EISDIR (Is a directory).
Where am I wrong using copyAsync?
Thanks