mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
write file on divice directory
This commit is contained in:
@@ -18,6 +18,6 @@
|
||||
}
|
||||
},
|
||||
"server": {
|
||||
"url": "http://192.168.1.5:8100"
|
||||
"url": "http://192.168.1.4:8100"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+7
@@ -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": {
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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<Attachment[]>{
|
||||
let geturl = environment.apiURL + 'attachments/GetAttachments';
|
||||
|
||||
Reference in New Issue
Block a user