download file on web fixed

This commit is contained in:
Equilibrium ITO
2024-03-18 12:59:41 +01:00
parent c08531a630
commit 75623da07e
5 changed files with 32 additions and 17 deletions
+11
View File
@@ -136,6 +136,7 @@
"duration": "^0.2.2", "duration": "^0.2.2",
"faker": "^5.5.3", "faker": "^5.5.3",
"fifo-process-queue": "^1.2.0", "fifo-process-queue": "^1.2.0",
"file-saver": "^2.0.5",
"firebase": "^8.10.1", "firebase": "^8.10.1",
"g": "^2.0.1", "g": "^2.0.1",
"global": "^4.4.0", "global": "^4.4.0",
@@ -16463,6 +16464,11 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/file-saver": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"node_modules/file-uri-to-path": { "node_modules/file-uri-to-path": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
@@ -56230,6 +56236,11 @@
"escape-string-regexp": "^1.0.5" "escape-string-regexp": "^1.0.5"
} }
}, },
"file-saver": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"file-uri-to-path": { "file-uri-to-path": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
+1
View File
@@ -152,6 +152,7 @@
"duration": "^0.2.2", "duration": "^0.2.2",
"faker": "^5.5.3", "faker": "^5.5.3",
"fifo-process-queue": "^1.2.0", "fifo-process-queue": "^1.2.0",
"file-saver": "^2.0.5",
"firebase": "^8.10.1", "firebase": "^8.10.1",
"g": "^2.0.1", "g": "^2.0.1",
"global": "^4.4.0", "global": "^4.4.0",
@@ -866,6 +866,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('RESULT', resultt.files[0].data) console.log('RESULT', resultt.files[0].data)
const blobb = this.fileService.base64toBlob(resultt.files[0].data, resultt.files[0].mimeType) const blobb = this.fileService.base64toBlob(resultt.files[0].data, resultt.files[0].mimeType)
const blob = new Blob([resultt.files[0].data], {type: resultt.files[0].mimeType});
const formDataa = new FormData(); const formDataa = new FormData();
formDataa.append('blobFile', blobb); formDataa.append('blobFile', blobb);
@@ -1034,11 +1034,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
downloadFileFromBrowser(fileName: string, data: any): void { downloadFileFromBrowser(fileName: string, data: any): void {
const linkSource = data; const link = document.createElement("a")
const downloadLink = document.createElement("a"); link.href = `data:${data.type}';base64,${data.image_url}`;
downloadLink.href = linkSource; link.download = fileName
downloadLink.download = fileName; link.click()
downloadLink.click();
link.remove()
} }
b64toBlob(b64Data, contentType) { b64toBlob(b64Data, contentType) {
@@ -1120,7 +1121,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}); });
modal.present(); modal.present();
} else { } else {
this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0].attachmentsUrl) this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0])
} }
} else { } else {
this.openFile(msg.attachments.image_url, msg.attachments[0].title, msg.file.type); this.openFile(msg.attachments.image_url, msg.attachments[0].title, msg.file.type);
@@ -35,6 +35,7 @@ import { ChatMessageDebuggingPage } from 'src/app/shared/popover/chat-message-de
import { PermissionService } from 'src/app/services/permission.service'; import { PermissionService } from 'src/app/services/permission.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service" import { FileValidatorService } from "src/app/services/file/file-validator.service"
import { ChangeDetectorRef } from '@angular/core'; import { ChangeDetectorRef } from '@angular/core';
import { saveAs } from 'file-saver';
const IMAGE_DIR = 'stored-images'; const IMAGE_DIR = 'stored-images';
@@ -1093,13 +1094,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
downloadFileFromBrowser(fileName: string, data: any): void { downloadFileFromBrowser(fileName: string, data: any): void {
const linkSource = data;
console.log('data in', data) const link = document.createElement("a")
const downloadLink = document.createElement("a"); link.href = `data:${data.type}';base64,${data.image_url}`;
downloadLink.href = linkSource; link.download = fileName
console.log('downloadLink.href',downloadLink.href) link.click()
downloadLink.download = fileName;
downloadLink.click(); link.remove()
} }
viewDocument(file: any, url?: string) { viewDocument(file: any, url?: string) {
@@ -1167,7 +1168,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}); });
modal.present(); modal.present();
} else { } else {
this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0].attachmentsUrl,) this.downloadFileFromBrowser(msg.attachments[0].title, msg.attachments[0],)
} }