showing results for - "uri 3a source 7brequire 28 60 24 7brnfs documentdirectorypath 7d 2f 60"
Ella
25 May 2020
1let filename = videoUrl.substring(deviceuri.lastIndexOf("/") + 1, videoUrl.length);
2let path_name = RNFS.DocumentDirectoryPath + filename;
3
4RNFS.exists(path_name).then(exists => {
5  if (exists) {
6    console.log("Already downloaded");
7  } else {
8    RNFS.downloadFile({
9      fromUrl: videoUrl,
10      toFile: path_name.replace(/%20/g, "_"),
11      background: true
12    })
13      .promise.then(res => {
14        console.log("File Downloaded", res);
15      })
16      .catch(err => {
17        console.log("err downloadFile", err);
18      });
19  }
20});
21
Montserrat
07 May 2017
1let fileName = videoURL.substring(videoURL.lastIndexOf("/") + 1, videoURL.length);
2
3this.getVideoUrl(videoURL, fileName)
4  .then(res => {
5    this.setState({ videoUri: res });
6  })
7  .catch(url => {
8    this.setState({ videoUri: url });
9  });
10
11
12getVideoUrl = (url, filename) => {
13  return new Promise((resolve, reject) => {
14    RNFS.readDir(RNFS.DocumentDirectoryPath)
15      .then(result => {
16        result.forEach(element => {
17          if (element.name == filename.replace(/%20/g, "_")) {
18            resolve(element.path);
19          }
20        });
21      })
22      .catch(err => {
23        reject(url);
24      });
25  });
26};
27