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 772 forks source link

Download and play a video file #684

Open TheRightGift opened 3 years ago

TheRightGift commented 3 years ago

Good day, This is not an issue, per say. It is more of a challenge I am facing using your documentation to learn. I want to be able to access downloaded videos but all i get is a successful download and the download path. I have not been able to play the video from that path. Please if i can be guided on how to achieve this i will be grateful. Thanks

aftabaminzoobiapps commented 3 years ago

I have an issue. I am downloading a video file that is downloading to all other folders for example Downloads, Music, but through an error.

unsupported path /storage/emulated/0/VideoDownloader/TikTok/TIKTOKVIDEO .

` const normaldownload = dispatch => async (url, foldername , name_prefix) =>{

    let mydirs = RNFetchBlob.fs.dirs.SDCardDir
      var date = new Date()
      let checkdir = await RNFetchBlob.fs.isDir(`${mydirs}/VideoDownloader/${foldername}`);
        if(!checkdir){
          RNFetchBlob.fs.mkdir(`${mydirs}/VideoDownloader/${foldername}`).then((res) =>{
            console.log('created', res)
          }).catch((error) =>{
                console.log('Error', error)
          })
        }else{
            console.log("Dir existss")
        }

        try{  
          let options = {
            fileCache: true,
            addAndroidDownloads : {
              useDownloadManager :true, // setting it to true will use the device's native download manager and will be shown in the notification bar.
              notification : true,
              mime : 'video/mp4',
              description : 'Downloading Video',
              path:  mydirs+`/VideoDownloader/${foldername}/${name_prefix}`+Math.floor(date.getTime() + date.getSeconds() / 2) + '.mp4', // this is the path where your downloaded file will live in
            }
          }
          PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,{
              title: "Storage",
              message: "This app would like to store some files on your phone"
            }).then( async () => {  
                RNFetchBlob.config(options).fetch('GET', url).then((res) => {
                  console.log('path of the downloads ')
                  ToastAndroid.showWithGravityAndOffset(
                    `File Saved in VideoDownloader/${foldername}😃 `,
                    ToastAndroid.LONG,
                    ToastAndroid.BOTTOM,
                    25,
                    50
                  )
                }).catch((error) =>{
                  console.log(error,'ERRRROR')
                  ToastAndroid.showWithGravityAndOffset(
                    `Download Failed`,
                    ToastAndroid.LONG,
                    ToastAndroid.BOTTOM,
                    25,
                    50
                  );
              })
            })
    }
    catch(error){
      console.log("Error in catch " , error)
    }
  }

`

The above code WOrking fine on android 9 ad less but it through Error on android 10. I have already added this line. android:requestLegacyExternalStorage="true"

Still no improvement.

aliergcr commented 3 years ago

Hi, did you try appendExt :'mp4' in options.

momenfnnana commented 2 years ago

same issue any update here?

ashirkhan94 commented 1 year ago

Same issue in IOS any update? thanks

kikipratiwi commented 11 months ago

any update folks? sorry to mention @TheRightGift @aftabaminzoobiapps @momenfnnana @ashirkhan94 🙏