joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 770 forks source link

IOS save to path results in no file #266

Open alpha0010 opened 5 years ago

alpha0010 commented 5 years ago

Upon upgrading from 0.10.13 to 0.10.14, saving to a specified file on IOS has stopped working.

let fullPath = RNFetchBlob.fs.dirs.DocumentDir + '/test.txt';
let res = await RNFetchBlob
  .config({ path: fullPath })
  .fetch('GET', 'https://raw.githubusercontent.com/joltup/rn-fetch-blob/master/.gitignore');
console.warn(fullPath);
console.warn(res.path());
console.warn(res.info());

Under both versions, the first two logs give the same result (something like [...]/Library/Developer/CoreSimulator/Devices/F3CE7938-1974-467C-8183-C1F98AC74CCE/data/Containers/Data/Application/8F3721D5-7CC6-4CEC-8D96-1AB6B4CB26E6/Documents/test.txt) and the last yields an object with the appropriate information (including status: 200).

If I navigate to [...]/Documents/ folder when the app is built with 0.10.13, text.txt exists. However, under 0.10.14, the folder remains empty.

cattuan commented 5 years ago

Same this issue when I upgrade from 0.10.13 to 0.10.14

JofBigHealth commented 5 years ago

Reverting to 0.10.13 fixes it and works perfectly for both operating systems for us.

Zoe3542188 commented 5 years ago

Same issue for new version

zhouxianjun commented 5 years ago

image image image image image image

the files of download is not exist

@Traviskn

wonday commented 5 years ago

+1 0.10.14 causes a bug: https://github.com/wonday/react-native-pdf/issues/286

Mcgode commented 5 years ago

Can confirm with both 'fileCache: true' and 'path: randomPath' options, on iOS 12.0, RN-fetch-blob 0.10.14 and RN ^0.55

benzman81 commented 5 years ago

Same here, went back to 0.10.13

legion-zver commented 5 years ago

Removed a piece of code responsible for saving the file to disk... All broke their new vision ((( And the most interesting, why?

https://github.com/joltup/rn-fetch-blob/commit/3aec4191f9661b78f5baf85da3f99ca1bd467a10#diff-f27851ca66016d2a5936b4dc68144330

legion-zver commented 5 years ago

@Traviskn need your help

Traviskn commented 5 years ago

@legion-zver Thanks for finding the root cause, I should have been more thorough in my code review before merging #198 I think I'll revert that merge

Traviskn commented 5 years ago

I have reverted #198 and published a new release, so file saving should be working again

Drckk commented 5 years ago

@Traviskn seems still not working

JasonFehr commented 5 years ago

Same, reverting to 0.10.13 fixed it for me

zhouxianjun commented 5 years ago

update to 0.10.15 fixed it for me.

vitorverasm commented 5 years ago

I'm in RN 0.57 and rn-fetch-blob 0.10.15. So when i try to download directly to a file with path: it returns response.path() correctly but there's no file. I don't know if i'm doing something wrong 😞 . I'm saving at DocumentDir on iOS.

EDIT: i've solved this by using WRITE_EXTERNAL_STORAGE permission on Android. And using this keys in info.plist for iOS:

<key> UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

As described here, to enable file sharing in the app Document folder.

phuoc-insignia commented 4 years ago

For those who are still strugling with this, I'm using CameraRoll on iOS to save image since it supports by default:

On iOS, the tag can be any image URI (including local, remote asset-library and base64 data URIs) or a local video file URI (remote or data URIs are not supported for saving video at this time).

If the tag has a file extension of .mov or .mp4, it will be inferred as a video. Otherwise it will be treated as a photo. To override the automatic choice, you can pass an optional type parameter that must be one of 'photo' or 'video'.

CameraRoll.saveToCameraRoll(
      'https://url.com/picture.jpg',
    ).then(Alert.alert('Success', 'Photo added to camera roll!'));
willnaoosmith commented 3 years ago

same here

rohitsainiidsil commented 3 years ago

Go to info.plist and add key "Application supports iTunes file sharing" and set Boolean value to YES. You will be able to see your downloads in "Files" of your iPhone. Screenshot 2020-08-27 at 4 08 17 PM

aliwaqar981 commented 3 years ago

I'm still facing this issue on 0.12.0 release. I'm trying download file in ios simulator 14.

let PictureDir = fs.dirs.PictureDir; let options = { fileCache: true, appendExt: 'png', path: PictureDir + '/image' + Math.floor(date.getTime()) + ext, addAndroidDownloads: { //Related to the Android only useDownloadManager: true, notification: true, path: PictureDir + '/image' + Math.floor(date.getTime() + date.getSeconds() / 2) + ext, description: 'Image', }, };

Above are my configs. Any help on this will be appreciated?

SodaisNasir commented 3 years ago

` const { dirs } = RNFetchBlob.fs; RNFetchBlob.config({ fileCache: true, notification: true, path: RNFetchBlob.fs.dirs.DocumentDir+"/taskmanagementApp/"+Math.random().toString(36)+fileName[2],

            })`

Please help god knows where it's saving in the emulator.

divityodaplus commented 1 year ago

what i got to know is first view the file in IOS and IOS automatically then gives option to save file this is my code

import FileViewer from "react-native-file-viewer";
import RNFS from 'react-native-fs';
export const downloadforIos = async (url) => {  // here url is your remote url
    const fileUrl =  url
    const fileName = url.substring(url.lastIndexOf('/')+1)
    const localFile = `${RNFS.DocumentDirectoryPath}/${fileName}`;
    if(fileUrl !== null){
        const options = {
        fromUrl: fileUrl,
        toFile: localFile
        };
        RNFS.downloadFile(options).promise
        .then(() => FileViewer.open(localFile))
        .then(() => {
        console.log("opened")
        // success
        })
        .catch(error => {
        // error
        console.log("error", error)
        notifyMessage("No app found to open this file type")
        });
    }
}