diff --git a/src/app/module/chat/domain/use-case/message/message-create-use-case.service.ts b/src/app/module/chat/domain/use-case/message/message-create-use-case.service.ts
index 697c1334e..f226326f2 100644
--- a/src/app/module/chat/domain/use-case/message/message-create-use-case.service.ts
+++ b/src/app/module/chat/domain/use-case/message/message-create-use-case.service.ts
@@ -125,13 +125,14 @@ export class MessageCreateUseCaseService {
this.AttachmentLocalRepositoryService.insert({
$messageId: createMessageLocally.value,
- base64: createDataURL(attachment.file, attachment.mimeType),
+ file: createBlobFromBase64(attachment.file, attachment.mimeType),
fileType: attachment.fileType,
source: attachment.source,
fileName: attachment.fileName,
applicationId: attachment.applicationId,
docId: attachment.docId,
mimeType: attachment.mimeType,
+
}).then((e) => {
if(e.isErr()) {
Logger.error('failed to create attachment locally on send message', {
diff --git a/src/app/ui/chat/component/messages/messages.page.ts b/src/app/ui/chat/component/messages/messages.page.ts
index 22efc7727..e694a77e4 100644
--- a/src/app/ui/chat/component/messages/messages.page.ts
+++ b/src/app/ui/chat/component/messages/messages.page.ts
@@ -1400,8 +1400,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
a.href = url;
a.download = fileName; // Set the desired file name
- // Programmatically click the element to trigger the download
- document.body.appendChild(a);
a.click();
} else {
const link = document.createElement("a")
@@ -1418,8 +1416,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.openViewDocumentModal(msg);
}
- openFile(pdfString, filename, type) {
- const blob = this.b64toBlob(pdfString, type)
+ openFile(blob: Blob, filename, type) {
let pathFile = ''
const fileName = filename
const contentFile = blob
@@ -1429,8 +1426,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
pathFile = this.file.externalRootDirectory
}
-
-
this.file
.writeFile(pathFile, fileName, contentFile, { replace: true })
.then(success => {
diff --git a/src/app/ui/chat/modal/messages/messages.page.ts b/src/app/ui/chat/modal/messages/messages.page.ts
index d6042b55a..0d06aa97e 100644
--- a/src/app/ui/chat/modal/messages/messages.page.ts
+++ b/src/app/ui/chat/modal/messages/messages.page.ts
@@ -1327,69 +1327,73 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
}
- downloadFileFromBrowser(fileName: string, data: any): void {
- const linkSource = data;
- const downloadLink = document.createElement("a");
- downloadLink.href = linkSource;
- downloadLink.download = fileName;
- downloadLink.click();
+ downloadFileFromBrowser(fileName: string, msg: MessageViewModal): void {
+ if(msg.attachments[0]?.blobURl) {
+ // Create a temporary URL for the Blob
+ const url = msg.attachments[0].safeFile;
+
+ // Create an element with the download attribute
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = fileName; // Set the desired file name
+
+ a.click();
+ } else {
+ const link = document.createElement("a")
+ link.href = `data:${msg.attachments[0].mimeType}';base64,${msg.attachments[0].safeFile}`;
+ link.download = fileName
+ link.click()
+
+ link.remove()
+ }
}
- async openPreview(msg) {
+ async openPreview(msg: MessageViewModal) {
- if (msg.file.type === "application/webtrix") {
- this.viewDocument(msg.file, msg.attachments.image_url)
+ if (msg.attachments[0].source === MessageAttachmentSource.Webtrix) {
+ this.viewDocument(msg)
} else {
- if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
- // this.downloadFileMsg(msg)
- // this.testDownlod(msg)
+ if (!msg.attachments[0].safeFile || msg.attachments[0].safeFile === null || msg.attachments[0].safeFile === '') {
+
} else {
- var str = msg.attachments[0].image_url;
- str = str.substring(1, ((str.length) - 1));
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
- console.log(msg)
-
- if (msg.file.type == "application/img") {
+ if (msg.attachments[0].mimeType.includes('image')) {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
- image: msg.attachments[0].image_url,
- type: msg.file.type,
- username: msg.u.name,
- _updatedAt: msg._updatedAt
+ image: msg.attachments[0].safeFile,
+ type: msg.attachments[0].mimeType,
+ username: msg.attachments[0].description,
+ _updatedAt: msg.sentAt
}
});
modal.present();
} else {
- this.downloadFileFromBrowser("file", str)
- this.downloadFileFromBrowser(msg.attachments[0].title, str)
-
- this.downloadFileFromBrowser(msg.attachments[0].title, str)
-
+ this.downloadFileFromBrowser(msg.attachments[0].description, msg)
}
} else {
- if (msg.file.type == "application/img") {
+ if (msg.attachments[0].mimeType.includes('image')) {
const modal = await this.modalController.create({
component: ViewMediaPage,
cssClass: 'modal modal-desktop',
componentProps: {
- image: msg.attachments[0].image_url,
- type: msg.file.type,
- username: msg.u.name,
- _updatedAt: msg._updatedAt
+ image: msg.attachments[0].safeFile,
+ type: msg.attachments[0].mimeType,
+ username: msg.attachments[0].description,
+ _updatedAt: msg.sentAt
}
});
modal.present();
} else {
- this.openFile(msg.attachments[0].image_url, msg.attachments[0].title, msg.file.type);
+ this.openFile(msg.attachments[0].safeFile, msg.attachments[0].description, msg.attachments[0].mimeType);
}
}