rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

How to specify a dir for iOS

Open franjorub opened this issue 6 years ago • 15 comments

I try with documents and download dirs but they return undefined, how should be the path for iOS ?

franjorub avatar Oct 13 '19 15:10 franjorub

https://github.com/joltup/rn-fetch-blob/wiki/File-System-Access-API#dirs Only DocumentDir, CacheDir, and MainBundleDir are available in iOS. I just tried RNFetchBlob.fs.mkdir(RNFetchBlob.fs.dirs.DocumentDir + '/' + uuid); with 0.10.5 and RN 0.59.9; works fine in the simulator without needing any additional permissions.

image

Transfusion avatar Nov 21 '19 02:11 Transfusion

@Transfusion Thanks but don't know where to find the files have tried opening the Files app but can't find anything there, although I'm working from an emulator not sure if that is an emulator limitation?

This is for a case where I'm downloading straight to a directory.

thecodecafe avatar Mar 24 '20 16:03 thecodecafe

@thecodecafe Same thing here, the file gets into the file system, but cannot access it through the file app, I am also beginning to think it is an emulator limitation, I'll try to get my hands on a physical device and let you know.

PaperbagWriter avatar Apr 02 '20 03:04 PaperbagWriter

@PaperbagWriter Tried it on a physical device and the files aren't showing up, plus I don't even think they get stored because after downloading to Documents I persist the download path for later but every time I run a check to see if the file exists, it doesn't, still looking into it to know what might be the cause though.

thecodecafe avatar Apr 02 '20 09:04 thecodecafe

@thecodecafe @PaperbagWriter Hi! Just walked by. But recently I worked with a similar story. You need permissions in info.plist that will be available for the system and other files. Here's what you need:

<key> LSSupportsOpeningDocumentsInPlace </key>
<Truth />
<key> UISupportsDocumentBrowser </key>
<Truth />
<key> UIFileSharingEnabled </key>
<Truth />

(the fact that in the middle is not necessary, but I decided it would be better).

JerakRus avatar Apr 02 '20 21:04 JerakRus

O wow thanks @JerakRus will try this in the morning at it's 11 pm here right now, thanks a bunch.

thecodecafe avatar Apr 02 '20 21:04 thecodecafe

Thanks @JerakRus it worked, I can now see the saved files in the File app on iOS.

thecodecafe avatar Apr 04 '20 08:04 thecodecafe

@thecodecafe Glad I could help!

JerakRus avatar Apr 04 '20 17:04 JerakRus

could be included @JerakRus answer in the docs ? I don't know if this is a common use case

franjorub avatar Apr 04 '20 20:04 franjorub

@thecodecafe @JerakRus Thanks that is great I actually thought it was not possible!

I also found that you can instead use

ios.previewDocument

After the file is downloaded into the cache without adding permissions, that way the user can decide where he wants to save it. It seems to feel more like the expected behavior on iOS.

For android you need to scan the files once they are downloaded in your directory of choice. Hope that helps.

PaperbagWriter avatar Apr 09 '20 13:04 PaperbagWriter

@thecodecafe @JerakRus Obrigado, isso é ótimo, na verdade pensei que não era possível!

Também descobri que você pode usar

ios.previewDocument

Após o download do arquivo para o cache sem adicionar permissões, o usuário pode decidir onde deseja salvá-lo. Parece mais com o comportamento esperado no iOS.

Para o Android, você precisa verificar os arquivos depois de baixá-los no diretório de sua escolha. Espero que ajude.

Sorry, I don't have an IOS emulator to test, but I would like to know what the correct solution is?

In your case just using ios.previewDocument can the user save the file where he wants?

In my case I want to save the file to a location on Android and IOS is the user's choice.

marquinmpfs avatar Sep 09 '20 15:09 marquinmpfs

@marquinmpfs
Hello! The permissions described above are used so that you can select a file from the device, and not for saving. They are not needed for your situation. But maybe others are needed, here I honestly won't tell you, I don't remember anymore =)

JerakRus avatar Sep 10 '20 17:09 JerakRus

@marquinmpfs Hello! The permissions described above are used so that you can select a file from the device, and not for saving. They are not needed for your situation. But maybe others are needed, here I honestly won't tell you, I don't remember anymore =)

Okay, thanks anyway.

marquinmpfs avatar Sep 17 '20 20:09 marquinmpfs

@JerakRus can you tell me in which directory to save the video file in ios??

Can we directly store into photos (MyAlbums) on ios, I tried CameraRoll.save but it is giving

The operation couldn’t be completed. (PHPhotosErrorDomain error 3302.

hussnainshafiul avatar Sep 05 '24 05:09 hussnainshafiul

@hussnainshafiul Hello, unfortunately my project does not include photo and video albums. But in order to view or cache the video, we save it in the same directories as regular files. I would find a solution to the errors in the libraries you indicated. For example, there are several options here https://github.com/react-native-cameraroll/react-native-cameraroll/issues/617

JerakRus avatar Sep 07 '24 12:09 JerakRus