Download file working

This commit is contained in:
Eudes Inácio
2021-12-23 07:40:01 +01:00
parent cff5ee4322
commit 8c20b62215
7 changed files with 96 additions and 38 deletions
@@ -146,15 +146,15 @@
<ion-fab-button (click)="bookMeeting()" color="light">
<ion-icon name="calendar"></ion-icon>
</ion-fab-button>
<!-- <ion-fab-button (click)="addFile()" color="light">
<ion-fab-button (click)="addFile()" color="light">
<ion-icon name="document"></ion-icon>
</ion-fab-button> -->
<!-- <ion-fab-button (click)="addImage()" color="light">
</ion-fab-button>
<ion-fab-button (click)="addImage()" color="light">
<ion-icon name="image"></ion-icon>
</ion-fab-button> -->
<!-- <ion-fab-button class="hide-desktop" (click)="takePicture()" color="light">
</ion-fab-button>
<ion-fab-button class="hide-desktop" (click)="takePicture()" color="light">
<ion-icon name="camera"></ion-icon>
</ion-fab-button> -->
</ion-fab-button>
<ion-fab-button (click)="addFileWebtrix()" color="light">
<ion-icon src="assets/icon/webtrix.svg"></ion-icon>
</ion-fab-button>
@@ -56,7 +56,7 @@
<div (click)="openPreview(msg)">
<!-- <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image" (click)="imageSize(file.image_url)"> -->
<img src="{{downloadFile}}" alt="image">
<img src={{msg.image_url}} alt="image">
</div>
<div>
<div class="file">
@@ -110,15 +110,15 @@
<ion-fab-button (click)="bookMeeting()" color="light">
<ion-icon name="calendar"></ion-icon>
</ion-fab-button>
<!-- <ion-fab-button hidden (click)="addFile()" color="light">
<ion-fab-button hidden (click)="addFile()" color="light">
<ion-icon name="document"></ion-icon>
</ion-fab-button> -->
<!-- <ion-fab-button (click)="addImage()" color="light">
</ion-fab-button>
<ion-fab-button (click)="addImage()" color="light">
<ion-icon name="image"></ion-icon>
</ion-fab-button> -->
<!-- <ion-fab-button (click)="takePicture()" color="light">
</ion-fab-button>
<ion-fab-button (click)="takePicture()" color="light">
<ion-icon name="camera"></ion-icon>
</ion-fab-button> -->
</ion-fab-button>
<ion-fab-button (click)="addFileWebtrix()" color="light">
<ion-icon src="assets/icon/webtrix.svg"></ion-icon>
</ion-fab-button>
+69 -16
View File
@@ -252,6 +252,9 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
transformData(res) {
let mgsArray = [];
res.forEach(async element => {
/* console.log('Web TRANSFORM MSG', element)
let image = await this.storageservice.get(element.file.guid);
console.log('IMAGE STORAGE', image) */
let chatmsg = {
_id: element._id,
@@ -264,17 +267,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
ts: element.ts,
u: element.u,
_updatedAt: element._updatedAt,
/* image_url: {
name: element.file.guid,
path: `${IMAGE_DIR}/${element.file.guid}`,
data: `data:image/jpeg;base64,${readFile.data}`,
}, */
/* image_url: image, */
}
mgsArray.push(chatmsg)
});
console.log('Web TRANSFORM MSG', mgsArray)
this.storageservice.store('chatmsg',mgsArray);
}
@@ -283,7 +284,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
//this.showLoader = true;
const roomId = this.roomId
this.chatService.getRoomMessages(this.roomId).subscribe(res => {
console.log(res);
console.log('ALL MSG FROM CHATROCK',res);
this.transformData(res['messages']);
this.getMessageDB();
//this.getFileFromLakeFS();
@@ -728,17 +729,69 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
card.el.style['z-index'] = 11;
}
downloadFileMsg(msg) {
console.log('FILE TYPE', msg.file.type)
this.downloadFile = "";
if (msg.file.type == "application/img") {
this.fileService.downloadFile(msg.file.guid).subscribe(async (event) => {
console.log('FILE TYPE 22', msg.file.guid)
var name = msg.file.guid;
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) {
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('FILE TYPE 44', this.downloadFile)
console.log('TRY ARRAY BUFFER NAME', name);
console.log('TRY ARRAY BUFFER', this.downloadFile);
this.storageservice.store(msg.file.guid,this.downloadFile);
await Filesystem.writeFile({
path: `${IMAGE_DIR}/${name}`,
data: this.downloadFile,
directory: Directory.Data
}).then((foo) => {
console.log('SAVED FILE WEB', foo)
}).catch((error) => {
console.log('SAVED FILE WEB error ', error)
});
const readFile = await Filesystem.readFile({
path: `${IMAGE_DIR}/${name}`,
directory: Directory.Data,
}).then((foo) => {
console.log('GET FILE WEB', foo)
});
}
});
console.log('FILE TYPE 44', this.downloadFile)
}
}
async openPreview(msg) {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present();
if(msg.image_url = "") {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
});
modal.present();
} else {
this.downloadFileMsg(msg)
}
}
}
@@ -6,9 +6,9 @@
</button>
</div>
<div class="buttons">
<button hidden (click)="takePicture()" full class="btn-ok" shape="round" >Tirar Fotografia</button>
<button hidden (click)="addFile()" class="btn-ok" shape="round" >Anexar Documento</button>
<button hidden (click)="anexarFoto()" full class="btn-ok" shape="round" >Anexar Fotografia</button>
<button (click)="takePicture()" full class="btn-ok" shape="round" >Tirar Fotografia</button>
<button (click)="addFile()" class="btn-ok" shape="round" >Anexar Documento</button>
<button (click)="anexarFoto()" full class="btn-ok" shape="round" >Anexar Fotografia</button>
<button (click)="addDocGestaoDocumental()" class="btn-ok" shape="round" >Gestão Documental</button>
<div class="solid"></div>
<button (click)="bookMeeting()" class="btn-ok" shape="round" >Novo Evento</button>