Image from camera web working fine

This commit is contained in:
Eudes Inácio
2022-01-27 15:53:20 +01:00
parent 7325a76718
commit 0b9efc3bf6
+53 -29
View File
@@ -254,43 +254,64 @@ export class FileService {
this.capturedImage = this.images[0].data
this.capturedImageTitle = new Date().getTime() + '.jpeg';
const base64 = await fetch(this.capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", this.capturedImage);
let guid: any = await this.uploadFile(this.capturedImage).toPromise()
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.uploadFile(formData).toPromise()
console.log(guid.path);
let body = {
"message":
{
"rid": roomid,
"msg": "",
"attachments": [{
"title": this.capturedImageTitle,
"title_link_download": false,
"image_url": this.capturedImage,
}],
"file":{
"type": "application/img",
"guid": guid.path,
"image_url": ""
this.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
//console.log('FILE TYPE 33', msg.file.type)
} else if (event.type === HttpEventType.Response) {
var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
let body = {
"message":
{
"rid": roomid,
"msg": "",
"attachments": [{
"title": this.capturedImageTitle,
"title_link_download": false,
"image_url": fileImage,
}],
"file":{
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
}
}
}
console.log('BODY TAKE PICTURE CHAT', body)
const loader = this.toastService.loading();
this.chatService.sendMessage(body).subscribe(res=> {
console.log(res);
loader.remove();
},(error) => {
loader.remove();
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
});
});
}
}
}
console.log('BODY TAKE PICTURE CHAT', body)
const loader = this.toastService.loading();
this.chatService.sendMessage(body).subscribe(res=> {
console.log(res);
loader.remove();
},(error) => {
loader.remove();
this.toastService.badRequest("Não foi possível adicionar a fotografia!");
});
});
}
async addCameraPictureToChat(roomId){
console.log('add camera to picture')
const image = await Camera.getPhoto({
quality: 50,
allowEditing: false,
@@ -300,6 +321,8 @@ export class FileService {
if (image) {
await this.saveImage(image,roomId)
} else {
console.log('Error saving image')
}
//this.capturedImage = this.capturedImage;
@@ -375,12 +398,13 @@ export class FileService {
const file = this.fileLoaderService.getFirstFile(input)
console.log(file);
console.log('first file',file);
const formData = new FormData();
formData.append("blobFile", file);
let guid: any = await this.uploadFile(formData).toPromise()
console.log('ADD IMAGE FORM DATA', formData)
console.log('add picture to chat', guid.path);
this.downloadFile(guid.path).subscribe(async (event) => {
@@ -390,7 +414,7 @@ export class FileService {
} else if (event.type === HttpEventType.Response) {
var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('add picture to chat',fileImage);
await this.storage.set(guid, fileImage).then(() => {
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
let body = {