mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Mobile add picture publiation and chat
This commit is contained in:
@@ -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
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user