feat(components): [el-upload] support put method (#3358)

This commit is contained in:
啝裳
2021-09-12 19:51:21 +08:00
committed by GitHub
parent 0327d2d0b2
commit da07d130da
9 changed files with 19 additions and 3 deletions

View File

@@ -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

View File

@@ -45,6 +45,10 @@ export default defineComponent({
type: Object as PropType<Headers>,
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,

View File

@@ -29,6 +29,7 @@ export interface ElUploadAjaxError extends Error {
export interface ElUploadRequestOptions {
action: string
method: string
data: Record<string, string | Blob>
filename: string
file: File

View File

@@ -68,6 +68,10 @@ export default defineComponent({
type: Object as PropType<Nullable<Partial<Headers>>>,
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) => {

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -412,6 +412,7 @@ fileList のスタイルを変更するには `list-type` を用いる。
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------- | ------------------------- | ------- |
| action | 必須、リクエスト URL | string | — | — |
| headers | リクエストヘッダ | object | — | — |
| method | アップロードリクエスト方法を設定する | string | post/put | post |
| multiple | 複数ファイルのアップロードが許可されているかどうか | boolean | — | — |
| data | リクエストの追加オプション | object | — | — |
| name | アップロードファイルのキー名 | string | — | file |

View File

@@ -428,6 +428,7 @@
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------- | ------------------------- | ------ |
| action | 必选参数,上传的地址 | string | — | — |
| headers | 设置上传的请求头部 | object | — | — |
| method | 设置上传的请求方法 | string | post/put | post |
| multiple | 是否支持多选文件 | boolean | — | — |
| data | 上传时附带的额外参数 | object | — | — |
| name | 上传的文件字段名 | string | — | file |