Created
June 5, 2019 08:54
-
-
Save CharlesGrimont/4d25bc74aebc6d79fe203947280611c6 to your computer and use it in GitHub Desktop.
Upload file angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {HttpClient} from "@angular/common/http"; | |
constructor(private http: HttpClient) { | |
} | |
public uploadFiles(url: string, from: any, headersObject: any){ | |
// here headers | |
let headers = new HttpHeaders(headersObject); | |
const httpRequest = new HttpRequest('POST', url, form, {reportProgress: true, withCredentials: true, headers: headers}); | |
this.http.request(httpRequest); | |
.subscribe(event => { | |
if (event.type === 1) { | |
// in progress | |
} else if (event instanceof HttpResponse) { | |
// upload finished | |
} | |
}, | |
error => { | |
this.handleErrorFileUpload(error, resolve); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment