let xhr = new XMLHttpRequest();
xhr.open('请求方法',fileURL);
xhr.setRequestHeader('Accept', fileType);
xhr.responseType = "blob";
xhr.onload = () => {
let file = new File([xhr.response], ‘fileName’, { type: fileType });
console.log(file)
};
xhr.send()
1、创建XMLHttpRequest对象,发起转换请求
2、open方法连接服务器
3、设置请求头accept为file的类型
4、设置响应头,响应类型为blob类型
5、使用file对象,将blob转换为file格式
6、send()发起请求