Skip to content

Commit

Permalink
Expose FormData object to UploadFile object
Browse files Browse the repository at this point in the history
  • Loading branch information
oleosjo authored and jkuri committed Aug 15, 2017
1 parent 52f4d7f commit 68522ec
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ngx-uploader/classes/ngx-uploader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface UploadFile {
name: string;
size: number;
type: string;
form: FormData;
progress: UploadProgress;
response?: any;
responseStatus?: number;
Expand Down Expand Up @@ -99,6 +100,7 @@ export class NgUploaderService {
name: file.name,
size: file.size,
type: file.type,
form: new FormData(),
progress: {
status: UploadStatus.Queue,
data: {
Expand Down Expand Up @@ -272,7 +274,6 @@ export class NgUploaderService {
xhr.open(method, url, true);
xhr.withCredentials = event.withCredentials ? true : false;

const form = new FormData();
try {
const uploadFile = this.fileList[file.fileIndex];
const uploadIndex = this.files.findIndex(file => file.nativeFile === uploadFile);
Expand All @@ -281,13 +282,13 @@ export class NgUploaderService {
observer.complete();
}

form.append(event.fieldName || 'file', uploadFile, uploadFile.name);
file.form.append(event.fieldName || 'file', uploadFile, uploadFile.name);

Object.keys(data).forEach(key => form.append(key, data[key]));
Object.keys(data).forEach(key => file.form.append(key, data[key]));
Object.keys(headers).forEach(key => xhr.setRequestHeader(key, headers[key]));

this.serviceEvents.emit({ type: 'start', file: file });
xhr.send(form);
xhr.send(file.form);
} catch (e) {
observer.complete();
}
Expand Down

0 comments on commit 68522ec

Please sign in to comment.