apps/Pre-site/src/app/services/file-upload.service.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 31
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 24
mnd 0
bc 0
fnc 2
dl 0
loc 31
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A FileUploadService.deleteImage 0 4 1
A FileUploadService.uploadImage 0 8 1
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