Save image
This commit is contained in:
44
projects/common/src/fm/services/image.service.ts
Normal file
44
projects/common/src/fm/services/image.service.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { IUser } from '../models/user';
|
||||
import { HttpClient,HttpHeaders } from "@angular/common/http";
|
||||
import { AppConfig } from "../shared/app.config";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ImageService {
|
||||
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
||||
}
|
||||
|
||||
ApiEndpoint() {
|
||||
return this.appConfig.getConfig("apiEndPoint");
|
||||
}
|
||||
|
||||
putImage(endpoint:string,blob:Blob) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', blob,blob.type);
|
||||
return this.httpClient.put<any>(endpoint,formData);
|
||||
}
|
||||
|
||||
b64toBlob(b64Data:string, contentType?:string):Blob {
|
||||
const sliceSize = 512;
|
||||
const byteCharacters = atob(b64Data);
|
||||
const byteArrays = [];
|
||||
|
||||
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
||||
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
||||
|
||||
const byteNumbers = new Array(slice.length);
|
||||
for (let i = 0; i < slice.length; i++) {
|
||||
byteNumbers[i] = slice.charCodeAt(i);
|
||||
}
|
||||
|
||||
const byteArray = new Uint8Array(byteNumbers);
|
||||
byteArrays.push(byteArray);
|
||||
}
|
||||
|
||||
const blob = new Blob(byteArrays, {type: contentType});
|
||||
return blob;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user