Skip to content

Commit

Permalink
fix(file-service): file upload xhr request status and response fix (c…
Browse files Browse the repository at this point in the history
…loses #722) (#729)
  • Loading branch information
saurabh1e authored and emoralesb05 committed Jul 3, 2017
1 parent 9180f99 commit 34ed963
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/platform/core/file/services/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class TdFileService {
*/
upload(options: IUploadOptions): Observable<any> {
return new Observable<any>((subscriber: Subscriber<any>) => {
let xhr: XMLHttpRequest = new XMLHttpRequest();
let xhr: XMLHttpRequest = new XMLHttpRequest();
let formData: FormData = new FormData();

if (options.file !== undefined) {
Expand All @@ -53,7 +53,7 @@ export class TdFileService {
formData = options.formData;
} else {
return subscriber.error('For [IUploadOptions] you have to set either the [file] or the [formData] property.');
}
}

xhr.upload.onprogress = (event: ProgressEvent) => {
let progress: number = 0;
Expand All @@ -65,8 +65,8 @@ export class TdFileService {

xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 201) {
subscriber.next(JSON.parse(xhr.response));
if (xhr.status >= 200 && xhr.status < 300) {
subscriber.next(xhr.response);
subscriber.complete();
} else {
subscriber.error(xhr.response);
Expand Down

0 comments on commit 34ed963

Please sign in to comment.