我试图下载一个 mp3 文件,它的名称在 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
我想下载151.20200706103512.mp3
文件。
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
})
作为回应,我得到了以下内容,其中包括 "Content-Description":"File Transfer", "Content-Disposition":"attachment; filename=151.20200706103512.mp3"。这里显示我的文件保存在 data 指定的目录中,但我在那里找不到任何文件。
{
"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"
}