diff --git a/src/components/Upload/src/UploadModal.vue b/src/components/Upload/src/UploadModal.vue index 81a37f20..41ed8619 100644 --- a/src/components/Upload/src/UploadModal.vue +++ b/src/components/Upload/src/UploadModal.vue @@ -187,8 +187,12 @@ item.status = UploadResultStatus.UPLOADING; const { data } = await props.api?.( { - ...(props.uploadParams || {}), + data: { + ...(props.uploadParams || {}), + }, file: item.file, + name: props.name, + filename: props.filename, }, function onUploadProgress(progressEvent: ProgressEvent) { const complete = ((progressEvent.loaded / progressEvent.total) * 100) | 0; diff --git a/src/components/Upload/src/props.ts b/src/components/Upload/src/props.ts index e1061fca..413b95d7 100644 --- a/src/components/Upload/src/props.ts +++ b/src/components/Upload/src/props.ts @@ -34,6 +34,14 @@ export const basicProps = { default: null, required: true, }, + name: { + type: String as PropType, + default: 'file', + }, + filename: { + type: String as PropType, + default: null, + }, }; export const uploadContainerProps = { diff --git a/src/utils/http/axios/Axios.ts b/src/utils/http/axios/Axios.ts index 086adb1e..113c32ae 100644 --- a/src/utils/http/axios/Axios.ts +++ b/src/utils/http/axios/Axios.ts @@ -5,7 +5,7 @@ import axios from 'axios'; import qs from 'qs'; import { AxiosCanceler } from './axiosCancel'; import { isFunction } from '/@/utils/is'; -import { cloneDeep, omit } from 'lodash-es'; +import { cloneDeep } from 'lodash-es'; import { ContentTypeEnum } from '/@/enums/httpEnum'; import { RequestEnum } from '/@/enums/httpEnum'; @@ -121,11 +121,17 @@ export class VAxios { */ uploadFile(config: AxiosRequestConfig, params: UploadFileParams) { const formData = new window.FormData(); + const customFilename = params.name || 'file'; + + if (params.filename) { + formData.append(customFilename, params.file, params.filename); + } else { + formData.append(customFilename, params.file); + } if (params.data) { Object.keys(params.data).forEach((key) => { - if (!params.data) return; - const value = params.data[key]; + const value = params.data![key]; if (Array.isArray(value)) { value.forEach((item) => { formData.append(`${key}[]`, item); @@ -133,15 +139,9 @@ export class VAxios { return; } - formData.append(key, params.data[key]); + formData.append(key, params.data![key]); }); } - formData.append(params.name || 'file', params.file, params.filename); - const customParams = omit(params, 'file', 'filename', 'file'); - - Object.keys(customParams).forEach((key) => { - formData.append(key, customParams[key]); - }); return this.axiosInstance.request({ ...config,