mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
Bug na visualização de ficheiro no tablet
This commit is contained in:
@@ -36,6 +36,7 @@ import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, Cur
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@Component({
|
||||
@@ -121,6 +122,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private sanitiser: DomSanitizer,
|
||||
private file: File,
|
||||
private platform: Platform,
|
||||
private fileOpener: FileOpener,
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
}
|
||||
@@ -967,27 +969,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
return blob;
|
||||
}
|
||||
|
||||
createFile(pdfString, filename, type) {
|
||||
const blob = this.b64toBlob(pdfString, type)
|
||||
let pathFile = ''
|
||||
const fileName = filename
|
||||
const contentFile = blob
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
pathFile = this.file.externalRootDirectory
|
||||
}
|
||||
console.log(pdfString)
|
||||
console.log(pathFile)
|
||||
console.log(contentFile)
|
||||
this.file
|
||||
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
||||
.then(success => {
|
||||
console.log('File is created');
|
||||
})
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
downloadFileFromBrowser(fileName: string, data: any): void {
|
||||
const linkSource = data;
|
||||
const downloadLink = document.createElement("a");
|
||||
@@ -1007,6 +988,30 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
}
|
||||
|
||||
openFile(pdfString, filename, type) {
|
||||
const blob = this.b64toBlob(pdfString, type)
|
||||
let pathFile = ''
|
||||
const fileName = filename
|
||||
const contentFile = blob
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
pathFile = this.file.externalRootDirectory
|
||||
}
|
||||
console.log(pdfString)
|
||||
console.log(pathFile)
|
||||
console.log(contentFile)
|
||||
this.file
|
||||
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
||||
.then(success => {
|
||||
this.fileOpener
|
||||
.open(pathFile + fileName, type)
|
||||
.then(() => console.log('File is opened'))
|
||||
.catch(e => console.log('Error opening file', e));
|
||||
})
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
async openPreview(msg) {
|
||||
console.log(msg);
|
||||
|
||||
@@ -1043,7 +1048,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
this.downloadFileFromBrowser(msg.attachments[0].name, str)
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
this.downloadFileFromBrowser(msg.attachments[0].name, str)
|
||||
} else if (this.platform.is('tablet')) {
|
||||
this.openFile(str, msg.attachments[0].name, msg.file.type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user