document preview working

This commit is contained in:
Equilibrium ITO
2024-03-11 13:21:44 +01:00
parent 5c9330254e
commit c49cd411e3
2 changed files with 8 additions and 5 deletions
+5 -5
View File
@@ -29,7 +29,7 @@ import { SessionStore } from 'src/app/store/session.service';
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page'; import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
import { File } from '@awesome-cordova-plugins/file/ngx'; import { File } from '@awesome-cordova-plugins/file/ngx';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx'; import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { Filesystem, Directory } from '@capacitor/filesystem'; import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { NewEventPage } from '../../agenda/new-event/new-event.page'; import { NewEventPage } from '../../agenda/new-event/new-event.page';
import { NotificationsService } from 'src/app/services/notifications.service'; import { NotificationsService } from 'src/app/services/notifications.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service' import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'
@@ -1106,11 +1106,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
async openFile(pdfString, filename, type) { async openFile(pdfString, filename, type) {
const blob = this.b64toBlob(pdfString, type)
console.log(blob)
let pathFile = '' let pathFile = ''
const fileName = filename const fileName = filename
const contentFile = blob
if (this.platform.is('ios')) { if (this.platform.is('ios')) {
pathFile = this.file.documentsDirectory pathFile = this.file.documentsDirectory
} else { } else {
@@ -1122,13 +1119,16 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
await Filesystem.writeFile({ await Filesystem.writeFile({
path: fileName, path: fileName,
data: pdfString, data: pdfString,
directory: Directory.Data, directory: Directory.Cache,
encoding: Encoding.UTF8,
}).then((dir) => { }).then((dir) => {
console.log('DIR ', dir) console.log('DIR ', dir)
this.fileOpener this.fileOpener
.open(dir.uri, type) .open(dir.uri, type)
.then(() => console.log()) .then(() => console.log())
.catch(e => console.error(e)) .catch(e => console.error(e))
}).catch((error) => {
console.log('error writing the file', error)
}); });
} }
+3
View File
@@ -448,6 +448,8 @@ export class MessageService {
let downloadFile = ""; let downloadFile = "";
this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => { this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => {
console.log('download file',event)
if (event.type === HttpEventType.DownloadProgress) { if (event.type === HttpEventType.DownloadProgress) {
} else if (event.type === HttpEventType.Response) { } else if (event.type === HttpEventType.Response) {
@@ -456,6 +458,7 @@ export class MessageService {
} else if (this.file.type != "application/img") { } else if (this.file.type != "application/img") {
downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
console.log('downloaded file', downloadFile)
} }