| Total Complexity | 2 |
| Complexity/F | 1 |
| Lines of Code | 31 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { HttpClient } from "@angular/common/http"; |
||
| 2 | import { Injectable } from "@angular/core"; |
||
| 3 | import { Observable } from "rxjs"; |
||
| 4 | import { environment } from "src/environments/environment"; |
||
| 5 | |||
| 6 | @Injectable({ |
||
| 7 | providedIn: "root" |
||
| 8 | }) |
||
| 9 | |||
| 10 | export class FileUploadService { |
||
| 11 | |||
| 12 | private baseUrl = `${environment.api+"image"+"?API_KEY="+environment.api_key}`; |
||
| 13 | |||
| 14 | constructor(private http: HttpClient) { } |
||
| 15 | |||
| 16 | uploadImage(file: File): Observable<any> { |
||
| 17 | let formData: any = new FormData(); |
||
| 18 | formData.append("image", file); |
||
| 19 | |||
| 20 | return this.http.post(this.baseUrl, formData, { |
||
| 21 | reportProgress: true, |
||
| 22 | observe: "events", |
||
| 23 | }); |
||
| 24 | } |
||
| 25 | |||
| 26 | deleteImage(name: string): Observable<any> { |
||
| 27 | const url = this.baseUrl+"&name="+name; |
||
| 28 | return this.http.delete(url); |
||
| 29 | } |
||
| 30 | } |
||
| 31 |