Download "Content-Disposition": "attachment; filename=example.mp3" in react-native

I was trying to download an mp3 file and it’s name specified in the URL.

https://aaaa&user=shanto3@gmail.com&pass=aaaa&device_id=0ef2c8496369ade1&input_text=Fine&lang=fr&output_file=151.20200706103512.mp3&info=tts_mp3

I want to download 151.20200706103512.mp3 file.

            RNFetchBlob
            .config({
                fileCache: true,
                appendExt: 'mp3'
            })
            .fetch('GET', url, {
                'Content-Type': 'multipart/form-data'
            })
            .then((res) => {
                console.log(res);
                let path = 'file://' + res.path()
                console.log(path);
            })
            .catch((errorMessage, statusCode) => {
                // error handling
            })

In response I’ve got the the following which includes
"Content-Description":"File Transfer",
"Content-Disposition":"attachment; filename=151.20200706103512.mp3"
. Here showing my file is saved in the directory specified by data but I don’t find any file there.

{
   "array":[
      "Function anonymous"
   ],
   "base64":[
      "Function anonymous"
   ],
   "blob":[
      "Function anonymous"
   ],
   "data":"/data/user/0/com.outlookguide/files/RNFetchBlobTmp_6ibat7y4nxc1wb96xeqcw.mp3",
   "flush":[
      "Function anonymous"
   ],
   "info":[
      "Function anonymous"
   ],
   "json":[
      "Function anonymous"
   ],
   "path":[
      "Function anonymous"
   ],
   "readFile":[
      "Function anonymous"
   ],
   "readStream":[
      "Function anonymous"
   ],
   "respInfo":{
      "headers":{
         "Cache-Control":"must-revalidate, post-check=0, pre-check=0",
         "Connection":"Keep-Alive",
         "Content-Description":"File Transfer",
         "Content-Disposition":"attachment; filename=151.20200706103512.mp3",
         "Content-Length":"4992",
         "Content-Transfer-Encoding":"binary",
         "Content-Type":"application/octet-stream",
         "Date":"Tue, 21 Jul 2020 06:10:57 GMT",
         "Expires":"0",
         "Keep-Alive":"timeout=5, max=100",
         "Pragma":"public",
         "Server":"Apache/2.4.29"
      },
      "redirects":[
      "https://aaaa&user=shanto3@gmail.com&pass=aaaa&device_id=0ef2c8496369ade1&input_text=Fine&lang=fr&output_file=151.20200706103512.mp3&info=tts_mp"
      ],
      "respType":"",
      "rnfbEncode":"path",
      "state":"2",
      "status":200,
      "taskId":"6ibat7y4nxc1wb96xeqcw",
      "timeout":false
   },
   "session":[
      "Function anonymous"
   ],
   "taskId":"6ibat7y4nxc1wb96xeqcw",
   "text":[
      "Function anonymous"
   ],
   "type":"path"
}

30 thoughts on “Download "Content-Disposition": "attachment; filename=example.mp3" in react-native”

  1. 915109 444630Its perfect time to make some plans for the future and it is time to be happy. Ive read this post and if I could I wish to suggest you some fascinating points or suggestions. Perhaps you could write next articles referring to this post. I want to read even much more points about it! 374666

    Reply

Leave a Comment