更新时间:2021-12-13 07:56:19
您可以在axios的响应中找到文件名
You can find your filename in the response of axios
var axios = require('axios')
var fs = require('fs')
axios({
method:'get',
url:'https://myapi.com/files/4hjiguo4ho45946794526975429',
responseType:'stream'
})
.then(function(response) {
let headerLine = response.data.headers['content-disposition']
let startFileNameIndex = headerLine.indexOf('"') + 1
let endFileNameIndex = headerLine.lastIndexOf('"')
let filename = headerLine.substring(startFileNameIndex, endFileNameIndex)
response.data.pipe(fs.createWriteStream(filename))
});
希望此回复对您有帮助