Download file from lake fs in progress

This commit is contained in:
Eudes Inácio
2021-12-17 17:20:43 +01:00
parent 5ca488e085
commit c10a69fc53
6 changed files with 85 additions and 19 deletions
+61 -11
View File
@@ -78,6 +78,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('recordbtn', { read: ElementRef }) recordBtn: ElementRef;
myAudio: any;
downloadfile: any;
downloadFile: any;
constructor(
public popoverController: PopoverController,
@@ -343,7 +344,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
viewDocument(file: any, url?: string) {
console.log(file);
if (file.type == "application/webtrix") {
this.openViewDocumentModal(file);
@@ -757,18 +757,68 @@ export class MessagesPage implements OnInit, 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.sqlservice.updateChatMsg(msg._id, 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.readdir({
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 != "") {
this.downloadFile();
} else {
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();
}
}