Create disableMultipart option in FileUploader
This commit is contained in:
@@ -22,6 +22,7 @@ export interface FileUploaderOptions {
|
|||||||
queueLimit?:number;
|
queueLimit?:number;
|
||||||
removeAfterUpload?:boolean;
|
removeAfterUpload?:boolean;
|
||||||
url?:string;
|
url?:string;
|
||||||
|
disableMultipart?:boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FileUploader {
|
export class FileUploader {
|
||||||
@@ -37,7 +38,8 @@ export class FileUploader {
|
|||||||
autoUpload: false,
|
autoUpload: false,
|
||||||
isHTML5: true,
|
isHTML5: true,
|
||||||
filters: [],
|
filters: [],
|
||||||
removeAfterUpload: false
|
removeAfterUpload: false,
|
||||||
|
disableMultipart: false
|
||||||
};
|
};
|
||||||
|
|
||||||
private _failFilterIndex:number;
|
private _failFilterIndex:number;
|
||||||
@@ -276,7 +278,7 @@ export class FileUploader {
|
|||||||
|
|
||||||
protected _xhrTransport(item:any):any {
|
protected _xhrTransport(item:any):any {
|
||||||
let xhr = item._xhr = new XMLHttpRequest();
|
let xhr = item._xhr = new XMLHttpRequest();
|
||||||
let form = new FormData();
|
let sendable:any;
|
||||||
this._onBeforeUploadItem(item);
|
this._onBeforeUploadItem(item);
|
||||||
// todo
|
// todo
|
||||||
/*item.formData.map(obj => {
|
/*item.formData.map(obj => {
|
||||||
@@ -287,9 +289,15 @@ export class FileUploader {
|
|||||||
if (typeof item._file.size !== 'number') {
|
if (typeof item._file.size !== 'number') {
|
||||||
throw new TypeError('The file specified is no longer valid');
|
throw new TypeError('The file specified is no longer valid');
|
||||||
}
|
}
|
||||||
this._onBuildItemForm(item, form);
|
if(!this.options.disableMultipart) {
|
||||||
|
sendable = new FormData();
|
||||||
|
this._onBuildItemForm(item, sendable);
|
||||||
|
|
||||||
|
sendable.append(item.alias, item._file, item.file.name);
|
||||||
|
} else {
|
||||||
|
sendable = item._file;
|
||||||
|
}
|
||||||
|
|
||||||
form.append(item.alias, item._file, item.file.name);
|
|
||||||
xhr.upload.onprogress = (event:any) => {
|
xhr.upload.onprogress = (event:any) => {
|
||||||
let progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
|
let progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
|
||||||
this._onProgressItem(item, progress);
|
this._onProgressItem(item, progress);
|
||||||
@@ -328,7 +336,7 @@ export class FileUploader {
|
|||||||
if (this.authToken) {
|
if (this.authToken) {
|
||||||
xhr.setRequestHeader('Authorization', this.authToken);
|
xhr.setRequestHeader('Authorization', this.authToken);
|
||||||
}
|
}
|
||||||
xhr.send(form);
|
xhr.send(sendable);
|
||||||
this._render();
|
this._render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user