Created
March 19, 2019 17:33
-
-
Save wesleygrimes/ea319b4c52f8178d562feb2d6fec6d41 to your computer and use it in GitHub Desktop.
ngrx-file-upload/src/app/file-upload.service.ts
This file contains 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, HttpEvent, HttpRequest } from '@angular/common/http'; | |
import { Injectable } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { environment } from 'src/environments/environment'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class FileUploadService { | |
private API_BASE_URL = environment.apiBaseUrl; | |
constructor(private httpClient: HttpClient) {} | |
public uploadFile(file: File): Observable<HttpEvent<{}>> { | |
const formData = new FormData(); | |
formData.append('files', file, file.name); | |
const options = { | |
reportProgress: true | |
}; | |
const req = new HttpRequest( | |
'POST', | |
`${this.API_BASE_URL}/api/file`, | |
formData, | |
options | |
); | |
return this.httpClient.request(req); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment