feat(multipart): Create disableMultipart option in FileUploader (#224)
* Create disableMultipart option in FileUploader * Add basic docs
This commit was merged in pull request #224.
This commit is contained in:
committed by
Dmitriy Shekhovtsov
parent
e068511917
commit
22307d266f
@@ -37,10 +37,11 @@ Follow me [ - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
||||||
|
|
||||||
Parameters that supported by this object:
|
Parameters supported by this object:
|
||||||
|
|
||||||
1. `url` - URL of File Uploader's route
|
1. `url` - URL of File Uploader's route
|
||||||
2. `authToken` - Auth token that will be applied as 'Authorization' header during file send.
|
2. `authToken` - Auth token that will be applied as 'Authorization' header during file send.
|
||||||
|
3. `disableMultipart` - If 'true', disable using a multipart form for file upload and instead stream the file. Some APIs (e.g. Amazon S3) may expect the file to be streamed rather than sent via a form. Defaults to false.
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export interface FileUploaderOptions {
|
|||||||
queueLimit?:number;
|
queueLimit?:number;
|
||||||
removeAfterUpload?:boolean;
|
removeAfterUpload?:boolean;
|
||||||
url?:string;
|
url?:string;
|
||||||
|
disableMultipart?:boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FileUploader {
|
export class FileUploader {
|
||||||
@@ -43,7 +44,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;
|
||||||
@@ -282,7 +284,7 @@ export class FileUploader {
|
|||||||
|
|
||||||
protected _xhrTransport(item:FileItem):any {
|
protected _xhrTransport(item:FileItem):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 => {
|
||||||
@@ -293,9 +295,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);
|
||||||
@@ -334,7 +342,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ import {FileSelectDirective, FileDropDirective, FileUploader} from 'ng2-file-upl
|
|||||||
|
|
||||||
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
|
||||||
|
|
||||||
Parameters that supported by this object:
|
Parameters supported by this object:
|
||||||
|
|
||||||
1. `url` - URL of File Uploader's route
|
1. `url` - URL of File Uploader's route
|
||||||
2. `authToken` - auth token that will be applied as 'Authorization' header during file send.
|
2. `authToken` - auth token that will be applied as 'Authorization' header during file send.
|
||||||
|
3. `disableMultipart` - If 'true', disable using a multipart form for file upload and instead stream the file. Some APIs (e.g. Amazon S3) may expect the file to be streamed rather than sent via a form. Defaults to false.
|
||||||
|
|
||||||
## FileDrop API
|
## FileDrop API
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user