Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ Follow me [![twitter](https://img.shields.io/twitter/follow/valorkin.svg?style=s

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

Expand Down
18 changes: 13 additions & 5 deletions components/file-upload/file-uploader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface FileUploaderOptions {
queueLimit?:number;
removeAfterUpload?:boolean;
url?:string;
disableMultipart?:boolean;
}

export class FileUploader {
Expand All @@ -37,7 +38,8 @@ export class FileUploader {
autoUpload: false,
isHTML5: true,
filters: [],
removeAfterUpload: false
removeAfterUpload: false,
disableMultipart: false
};

private _failFilterIndex:number;
Expand Down Expand Up @@ -276,7 +278,7 @@ export class FileUploader {

protected _xhrTransport(item:any):any {
let xhr = item._xhr = new XMLHttpRequest();
let form = new FormData();
let sendable:any;
this._onBeforeUploadItem(item);
// todo
/*item.formData.map(obj => {
Expand All @@ -287,9 +289,15 @@ export class FileUploader {
if (typeof item._file.size !== 'number') {
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) => {
let progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
this._onProgressItem(item, progress);
Expand Down Expand Up @@ -328,7 +336,7 @@ export class FileUploader {
if (this.authToken) {
xhr.setRequestHeader('Authorization', this.authToken);
}
xhr.send(form);
xhr.send(sendable);
this._render();
}

Expand Down
3 changes: 2 additions & 1 deletion components/file-upload/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Parameters that supported by this object:
Parameters supported by this object:

1. `url` - URL of File Uploader's route
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

Expand Down