Mobile add picture publiation and chat

This commit is contained in:
Eudes Inácio
2022-02-03 16:36:05 +01:00
parent 8e0fad9c99
commit 99b33375b8
7 changed files with 81 additions and 33 deletions
+55 -17
View File
@@ -41,6 +41,7 @@ export class FileService {
headers: HttpHeaders;
downloadProgess = 0;
downloadFilename: any;
convertBlobToBase64Worker;
constructor(
private fileLoaderService: FileLoaderService,
@@ -146,27 +147,64 @@ export class FileService {
reader.readAsDataURL(blob);
});
async loadPicture() {
const input = this.fileLoaderService.createInput({
accept: ['image/apng', 'image/jpeg', 'image/png', '.pdf']
})
async loadPicture(roomid) {
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Photos
});
input.onchange = async () => {
const file = this.fileLoaderService.getFirstFile(input)
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.uploadFile(formData).toPromise()
console.log(guid.path);
console.log(file);
const imageData = await this.fileToBase64Service.convert(file)
this.capturedImage = imageData;
this.capturedImageTitle = file.name;
this.downloadFile(guid.path).subscribe(async (event) => {
let data = {
image:this.capturedImage,
name: this.capturedImageTitle
}
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!");
});
return data;
};
});
}
});
}
//new method1
@@ -336,7 +374,7 @@ export class FileService {
quality: 50,
// allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Camera
source: CameraSource.Photos
});