title: Download stream file from server with react-native-fs module in React Native
body: <p>I want to download file created dynamically from server, the file is created with this config in php</p>
  
  <pre><code>header('Content-Type: "' . $mime . '"');
          header('Content-Disposition: attachment; filename="' . $title .".". $ext . '"');
          header('Expires: 0');
          header('Content-Length: '.$size);
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header("Content-Transfer-Encoding: binary");
          header('Pragma: public');
  readfile($file);
  </code></pre>
  
  <p>I have tried with something like this in react native</p>
  
  <pre><code>const tmpFName      = res.data.media_url.split('/').pop();
  const fName         = tmpFName.split('?')[0];
  const resultFile    =  `${RNFS.TemporaryDirectoryPath}/${fName}`;
  
  RNFS.downloadFile({
          fromUrl : res.data.media_url,
          toFile  : resultFile,
      }).promise.then(async (r) =&gt; {
          CameraRoll.saveToCameraRoll(resultFile, res.data.label).then((dt) =&gt; {
              this.setState({
                  loading     : false,
                  loadingTitle: 'Loading Content',
                  isLoaded    : false,
                  isDone      : true
              });
  
              //Alert.alert("Saved");
  
          }).catch((err) =&gt; {
              this.setState({
                  text : '',
                  loading: false,
                  isError: true,
                  errorMessage: err.toString(),
                  errorTitle: 'Saving ' + res.data.label + ' failed'
              });
          });
  
      }).catch((err) =&gt; {
          this.setState({text: '',loading : false, isError: true, errorMessage : err.toString(), errorTitle: 'Download failed'});
      });
  </code></pre>
  
  <p>But it gives me error </p>
  
  <blockquote>
    <p>Error : unsupported URL</p>
  </blockquote>
  
  <p>But if the url executed via browser, it does download file correctly.
  Please can someone help me with this ?</p>
  
  <p>the link is look like this
  <code>http://dislh.sumutprov.go.id/iklh/my/yt/download.php?url=aHR0cHM6Ly9yMi0tLXNuLW8wbjVveHUtaHhuZS5nb29nbGV2aWRlby5jb20vdmlkZW9wbGF5YmFjaz9leHBpcmU9MTU2OTg2MTg5NiZlaT1wOXlSWFktOE9lakozTFVQLTdhZi1BTSZpcD0xMTAuMjMyLjg3LjE1NCZpZD1vLUFDQm9aTDI2QU5lNlczZEdXZDItaVNJM2hQV1R3aWVwbXFH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