mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
Image from camera web working fine
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user