mirror of https://github.com/ElemeFE/element
Upload: fix Error when `beforeUpload` hook return promise of file object (#11297)
* Upload: fix beforeUpload hook bug * Upload: add ElUploadInternalRawFile interfacepull/11320/head
parent
bc75c14dac
commit
2a1a6360ca
|
@ -94,8 +94,16 @@ export default {
|
||||||
const fileType = Object.prototype.toString.call(processedFile);
|
const fileType = Object.prototype.toString.call(processedFile);
|
||||||
|
|
||||||
if (fileType === '[object File]' || fileType === '[object Blob]') {
|
if (fileType === '[object File]' || fileType === '[object Blob]') {
|
||||||
processedFile.name = rawFile.name;
|
if (fileType === '[object Blob]') {
|
||||||
processedFile.uid = rawFile.uid;
|
processedFile = new File([processedFile], rawFile.name, {
|
||||||
|
type: rawFile.type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const p in rawFile) {
|
||||||
|
if (rawFile.hasOwnProperty(p)) {
|
||||||
|
processedFile[p] = rawFile[p];
|
||||||
|
}
|
||||||
|
}
|
||||||
this.post(processedFile);
|
this.post(processedFile);
|
||||||
} else {
|
} else {
|
||||||
this.post(rawFile);
|
this.post(rawFile);
|
||||||
|
|
|
@ -9,13 +9,17 @@ export interface FileListItem {
|
||||||
status?: FileUploadStatus
|
status?: FileUploadStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ElUploadInternalRawFile extends File {
|
||||||
|
uid: number
|
||||||
|
}
|
||||||
|
|
||||||
export interface ElUploadInternalFileDetail {
|
export interface ElUploadInternalFileDetail {
|
||||||
status: FileUploadStatus,
|
status: FileUploadStatus,
|
||||||
name: string,
|
name: string,
|
||||||
size: number,
|
size: number,
|
||||||
percentage: number,
|
percentage: number,
|
||||||
uid: number,
|
uid: number,
|
||||||
raw: File,
|
raw: ElUploadInternalRawFile,
|
||||||
url?: string
|
url?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +87,7 @@ export declare class ElUpload extends ElementUIComponent {
|
||||||
onChange: (file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail[]) => void
|
onChange: (file: ElUploadInternalFileDetail, fileList: ElUploadInternalFileDetail[]) => void
|
||||||
|
|
||||||
/** Hook function before uploading with the file to be uploaded as its parameter. If false or a Promise is returned, uploading will be aborted */
|
/** Hook function before uploading with the file to be uploaded as its parameter. If false or a Promise is returned, uploading will be aborted */
|
||||||
beforeUpload: (file: ElUploadInternalFileDetail) => boolean | Promise<File | boolean>
|
beforeUpload: (file: ElUploadInternalRawFile) => boolean | Promise<File | Blob | boolean>
|
||||||
|
|
||||||
/** Whether thumbnail is displayed */
|
/** Whether thumbnail is displayed */
|
||||||
thumbnailMode: boolean
|
thumbnailMode: boolean
|
||||||
|
|
Loading…
Reference in New Issue