feat(file): 下载404(待解决)

This commit is contained in:
萌狼蓝天 2025-03-14 17:53:05 +08:00
parent c7f5936a5b
commit e94c50a543
2 changed files with 8 additions and 3 deletions

View File

@ -15,9 +15,9 @@ export function uploadFile(file) {
// 文件下载接口(需要处理二进制流) // 文件下载接口(需要处理二进制流)
export function downloadFile(fileId) { export function downloadFile(fileId) {
return axiosInstance.get(`/file/files/${fileId}`, { return get(`/file/files/${fileId}`, {
responseType: 'blob', // 指定响应类型为二进制流 // responseType: 'blob', // 指定响应类型为二进制流
timeout: 15000 // 下载超时时间延长至15秒 // timeout: 15000 // 下载超时时间延长至15秒
}); });
} }

View File

@ -154,6 +154,11 @@ const beforeUpload = async file => {
const handleDownload = async record => { const handleDownload = async record => {
try { try {
const response = await downloadFile(record._id) const response = await downloadFile(record._id)
console.log(response)
if(response.code === -1) {
message.error('下载失败,文件不存在')
return
}
const url = window.URL.createObjectURL(new Blob([response])) const url = window.URL.createObjectURL(new Blob([response]))
const link = document.createElement('a') const link = document.createElement('a')
link.href = url link.href = url