You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
573 B
21 lines
573 B
const axios = require('axios');
|
|
|
|
//下载资源文件流
|
|
async function downloadFileToBuffer(url) {
|
|
try {
|
|
// 发起 GET 请求并设置 responseType 为 'arraybuffer'
|
|
const response = await axios({
|
|
method: 'get',
|
|
url,
|
|
responseType: 'arraybuffer'
|
|
});
|
|
console.log("数据流", response.data);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(`Error downloading file from ${url}: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
downloadFileToBuffer: downloadFileToBuffer
|
|
}
|
|
|