Skip to content

Instantly share code, notes, and snippets.

@CharlesGrimont
Created June 5, 2019 08:54
Show Gist options
  • Save CharlesGrimont/4d25bc74aebc6d79fe203947280611c6 to your computer and use it in GitHub Desktop.
Save CharlesGrimont/4d25bc74aebc6d79fe203947280611c6 to your computer and use it in GitHub Desktop.
Upload file angular
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