diff --git a/packages/components/upload/src/ajax.ts b/packages/components/upload/src/ajax.ts index 731653f362..4aa2f62741 100644 --- a/packages/components/upload/src/ajax.ts +++ b/packages/components/upload/src/ajax.ts @@ -16,12 +16,12 @@ function getError( } else if (xhr.responseText) { msg = `${xhr.responseText}` } else { - msg = `fail to post ${action} ${xhr.status}` + msg = `fail to ${option.method} ${action} ${xhr.status}` } const err = new Error(msg) as ElUploadAjaxError err.status = xhr.status - err.method = 'post' + err.method = option.method err.url = action return err } @@ -78,7 +78,7 @@ export default function upload(option: ElUploadRequestOptions) { option.onSuccess(getBody(xhr)) } - xhr.open('post', action, true) + xhr.open(option.method, action, true) if (option.withCredentials && 'withCredentials' in xhr) { xhr.withCredentials = true diff --git a/packages/components/upload/src/index.vue b/packages/components/upload/src/index.vue index 669fc95bd7..2836da3d04 100644 --- a/packages/components/upload/src/index.vue +++ b/packages/components/upload/src/index.vue @@ -45,6 +45,10 @@ export default defineComponent({ type: Object as PropType, default: () => ({}), }, + method: { + type: String, + default: 'post', + }, data: { type: Object, default: () => ({}), @@ -214,6 +218,7 @@ export default defineComponent({ 'before-upload': this.beforeUpload, 'with-credentials': this.withCredentials, headers: this.headers, + method: this.method, name: this.name, data: this.data, accept: this.accept, diff --git a/packages/components/upload/src/upload.type.ts b/packages/components/upload/src/upload.type.ts index beb8481573..e6d92c12a9 100644 --- a/packages/components/upload/src/upload.type.ts +++ b/packages/components/upload/src/upload.type.ts @@ -29,6 +29,7 @@ export interface ElUploadAjaxError extends Error { export interface ElUploadRequestOptions { action: string + method: string data: Record filename: string file: File diff --git a/packages/components/upload/src/upload.vue b/packages/components/upload/src/upload.vue index 6cca72ea26..528dc7b828 100644 --- a/packages/components/upload/src/upload.vue +++ b/packages/components/upload/src/upload.vue @@ -68,6 +68,10 @@ export default defineComponent({ type: Object as PropType>>, default: () => null, }, + method: { + type: String, + default: 'post', + }, withCredentials: { type: Boolean, default: false, @@ -228,6 +232,7 @@ export default defineComponent({ withCredentials: props.withCredentials, file: rawFile, data: props.data, + method: props.method, filename: props.name, action: props.action, onProgress: (e) => { diff --git a/website/docs/en-US/upload.md b/website/docs/en-US/upload.md index 84d7ac65cd..a78d63483e 100644 --- a/website/docs/en-US/upload.md +++ b/website/docs/en-US/upload.md @@ -412,6 +412,7 @@ You can drag your file to a certain area to upload it. | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ------------------------- | ------- | | action | required, request URL | string | — | — | | headers | request headers | object | — | — | +| method | set upload request method | string | post/put | post | | multiple | whether uploading multiple files is permitted | boolean | — | — | | data | additions options of request | object | — | — | | name | key name for uploaded file | string | — | file | diff --git a/website/docs/es/upload.md b/website/docs/es/upload.md index f7a6beb3b0..18b00e97bf 100644 --- a/website/docs/es/upload.md +++ b/website/docs/es/upload.md @@ -418,6 +418,7 @@ Puede arrastrar el archivo dentro de un área en especifico para cargar el archi | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ------------------------- | ----------- | | action | obligatorio, URL de la petición | string | — | — | | headers | cabeceras de la petición | object | — | — | +| method | establecer método de solicitud de carga | string | post/put | post | | multiple | especifica si se permite subir múltiples archivos | boolean | — | — | | data | opciones adicionales de la petición | object | — | — | | name | nombre clave del archivo | string | — | file | diff --git a/website/docs/fr-FR/upload.md b/website/docs/fr-FR/upload.md index 242e45f6ea..a6cad496d8 100644 --- a/website/docs/fr-FR/upload.md +++ b/website/docs/fr-FR/upload.md @@ -422,6 +422,7 @@ Vous pouvez déposer les fichiers par drag'n drop sur l'espace dédié. | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ------------------------- | ------ | | action | Requis, l'url de requête. | string | — | — | | headers | Les headers de la requête. | object | — | — | +| method | Définir la méthode de demande de téléchargement | string | post/put | post | | multiple | Si envoyer de multiples fichiers est autorisé. | boolean | — | — | | data | Options additionnelles de la requête. | object | — | — | | name | Identifiant du fichier. | string | — | file | diff --git a/website/docs/jp/upload.md b/website/docs/jp/upload.md index b4f76c9417..4886c878d6 100644 --- a/website/docs/jp/upload.md +++ b/website/docs/jp/upload.md @@ -412,6 +412,7 @@ fileList のスタイルを変更するには `list-type` を用いる。 | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------- | ------------------------- | ------- | | action | 必須、リクエスト URL | string | — | — | | headers | リクエストヘッダ | object | — | — | +| method | アップロードリクエスト方法を設定する | string | post/put | post | | multiple | 複数ファイルのアップロードが許可されているかどうか | boolean | — | — | | data | リクエストの追加オプション | object | — | — | | name | アップロードファイルのキー名 | string | — | file | diff --git a/website/docs/zh-CN/upload.md b/website/docs/zh-CN/upload.md index e659f32117..25c0384e98 100644 --- a/website/docs/zh-CN/upload.md +++ b/website/docs/zh-CN/upload.md @@ -428,6 +428,7 @@ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------- | ------------------------- | ------ | | action | 必选参数,上传的地址 | string | — | — | | headers | 设置上传的请求头部 | object | — | — | +| method | 设置上传的请求方法 | string | post/put | post | | multiple | 是否支持多选文件 | boolean | — | — | | data | 上传时附带的额外参数 | object | — | — | | name | 上传的文件字段名 | string | — | file |