diff --git a/android/app/src/main/assets/capacitor.config.json b/android/app/src/main/assets/capacitor.config.json index f9d5f88c0..50814d988 100644 --- a/android/app/src/main/assets/capacitor.config.json +++ b/android/app/src/main/assets/capacitor.config.json @@ -18,6 +18,6 @@ } }, "server": { - "url": "http://192.168.1.5:8100" + "url": "http://192.168.1.4:8100" } } diff --git a/package-lock.json b/package-lock.json index 84f153db9..7b7929d9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3063,6 +3063,13 @@ "integrity": "sha512-3t7UhcqNxZuIX+HXuydlaDfA9AwDXiRFGs9GsHpJnXMTfbeKUcwzp0amqblrLslDA9tNfqSmJyFZFaMX6CRrog==", "requires": { "@types/cordova": "^0.0.34" + }, + "dependencies": { + "@types/cordova": { + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", + "integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ=" + } } }, "@ionic-native/image-picker": { diff --git a/package.json b/package.json index 25f754e7e..f957e317b 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@ionic-native/file": "^5.36.0", "@ionic-native/file-path": "^5.30.0", "@ionic-native/fingerprint-aio": "^4.20.0", - "@ionic-native/http": "^5.31.1", + "@ionic-native/http": "^5.36.0", "@ionic-native/image-picker": "^5.36.0", "@ionic-native/in-app-browser": "^5.28.0", "@ionic-native/ionic-webview": "^5.36.0", diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 9da9cf2da..6a29b7e7d 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -94,6 +94,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { myAudio: any; downloadfile: any; downloadFile: any; + downloadProgess: number; constructor( public popoverController: PopoverController, @@ -687,7 +688,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { console.log('Add file blob', blob) const formData = new FormData(); - formData.append("blobFile", blob); + formData.append("blobFile", blob2); this.wsChatMethodsService.getDmRoom(roomId).send({ file: { @@ -820,6 +821,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } + testeDownload(msg: MessageService) { + this.downloadFile = ""; + this.AttachmentsService.downloadFileAndStore(msg.file.guid); + } + downloadFileMsg(msg: MessageService) { console.log('FILE TYPE', msg.file.type) @@ -830,7 +836,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { var name = msg.file.guid; if (event.type === HttpEventType.DownloadProgress) { - //this.downloadProgess = Math.round((100 * event.loaded) / event.total); + this.downloadProgess = Math.round((100 * event.loaded) / event.total); + console.log(this.downloadProgess) console.log('FILE TYPE 33', msg.file.type) } else if (event.type === HttpEventType.Response) { if (msg.file.type == "application/img") { @@ -856,11 +863,15 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } + testDownlod(msg: MessageService) { + this.AttachmentsService.downloadFileAndStore(msg.file.guid) + } + async openPreview(msg) { console.log(msg); if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { - this.downloadFileMsg(msg) + this.testDownlod(msg) } else { const modal = await this.modalController.create({ diff --git a/src/app/services/attachments.service.ts b/src/app/services/attachments.service.ts index 2beeaef61..3c2902df5 100644 --- a/src/app/services/attachments.service.ts +++ b/src/app/services/attachments.service.ts @@ -5,6 +5,8 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { environment } from 'src/environments/environment'; import { LoginUserRespose } from '../models/user.model'; import { SessionStore } from '../store/session.service'; +import { File } from '@ionic-native/file/ngx'; +import { Platform } from '@ionic/angular'; @Injectable({ providedIn: 'root' @@ -14,7 +16,7 @@ export class AttachmentsService { loggeduser: LoginUserRespose; headers: HttpHeaders; - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private platform: Platform, private file: File) { this.loggeduser = SessionStore.user this.headers = new HttpHeaders(); this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey); @@ -60,6 +62,29 @@ export class AttachmentsService { }) } + + downloadFileAndStore(guid:any) { + var name = new Date().getTime(); + const downloadPath = ( + this.platform.is('android') + ) ? this.file.externalDataDirectory : this.file.documentsDirectory; + + + let vm = this; + + /** HttpClient - @angular/common/http */ + this.http.get( + environment.apiURL +'objectserver/streamfiles?path='+guid, + { + responseType: 'arraybuffer', + } + ).subscribe((fileBlob: Uint8Array) => { + /** File - @ionic-native/file/ngx */ + vm.file.writeFile(downloadPath, "YourFileName.pdf", fileBlob, {replace: true}); + console.log(downloadPath +"/"+"YourFileName.pdf") + console.log(fileBlob) + }); + } getAttachmentsBySerial(serialNumber: string): Observable{ let geturl = environment.apiURL + 'attachments/GetAttachments';