argos/dmp-frontend/src/app/services/files/project-file-uploader.servi...

31 lines
1.0 KiB
TypeScript
Raw Normal View History

2018-11-27 15:13:56 +01:00
import { HttpHeaders } from '@angular/common/http';
2018-03-21 14:15:06 +01:00
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
2018-11-27 15:13:56 +01:00
import 'rxjs/add/operator/map';
import { environment } from '../../../environments/environment';
2018-05-14 08:44:35 +02:00
import { ContentFile } from '../../models/files/ContentFile';
2018-11-27 15:13:56 +01:00
import { FileUploader } from '../../shared/components/file-uploader/FileUploader';
import { BaseHttpService } from '../../utilities/cite-http-service-module/base-http.service';
2018-03-21 14:15:06 +01:00
@Injectable()
export class ProjectFileUploaderService implements FileUploader {
2018-10-05 17:00:54 +02:00
private actionUrl: string;
private headers: HttpHeaders;
2018-03-21 14:15:06 +01:00
2018-10-05 17:00:54 +02:00
constructor(private http: BaseHttpService) {
2018-03-21 14:15:06 +01:00
2018-11-27 15:13:56 +01:00
this.actionUrl = environment.Server + 'files/';
2018-03-21 14:15:06 +01:00
2018-10-05 17:00:54 +02:00
this.headers = new HttpHeaders();
this.headers = this.headers.set('Content-Type', 'application/json');
this.headers = this.headers.set('Accept', 'application/json');
}
2018-03-21 14:15:06 +01:00
2018-10-05 17:00:54 +02:00
uploadFile(formData: FormData): Observable<ContentFile> {
return this.http.post(this.actionUrl + 'upload', formData, this.headers);
}
2018-03-21 14:15:06 +01:00
}