This commit is contained in:
Peter Maquiran
2023-08-28 13:00:51 +01:00
parent 774178108c
commit fbc02a0585
3 changed files with 132 additions and 52 deletions
+40 -17
View File
@@ -645,8 +645,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
source: CameraSource.Camera
});
const base64 = 'data:image/jpeg;base64,' + file.base64String
const blob = this.dataURItoBlob(base64)
const imageBase64 = 'data:image/jpeg;base64,' + file.base64String
const blob = this.dataURItoBlob(imageBase64)
console.log(imageBase64)
const formData = new FormData();
formData.append("blobFile", blob);
@@ -665,7 +667,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"title_link_download": false,
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: imageBase64,
}
})
@@ -675,13 +677,18 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const roomId = this.roomId
const image = await this.CameraService.takePicture();
await this.fileService.saveImage(image);
const lastphoto: any = await this.fileService.loadFiles();
const { capturedImage, capturedImageTitle } = await this.fileService.loadFileData(lastphoto);
const base64 = await fetch(capturedImage);
const file = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Base64,
source: CameraSource.Camera
});
const imageBase64 = 'data:image/jpeg;base64,' + file.base64String
const blob = this.dataURItoBlob(imageBase64)
console.log(imageBase64)
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
@@ -693,13 +700,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
},
temporaryData: formData,
attachments: [{
"title": capturedImageTitle,
"image_url": capturedImage,
"title": "file.jpg",
"text": "description",
"title_link_download": false,
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: imageBase64,
}
})
@@ -770,10 +776,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
//const imageData = await this.fileToBase64Service.convert(file)
//
const response = await fetch('data:image/jpeg;base64,' + file.base64String!);
const imageBase64 = 'data:image/jpeg;base64,' + file.base64String
const response = await fetch(imageBase64);
const blob = await response.blob();
console.log(imageBase64)
const formData = new FormData();
formData.append("blobFile", blob);
@@ -790,7 +798,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"title_link_download": false,
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: imageBase64,
}
})
@@ -805,6 +813,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const file: any = await this.fileService.getFileFromDevice(types);
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
@@ -812,9 +821,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
})));
const blob = this.fileService.base64toBlob(encodedData, file.type)
const fileBase64 = await this._getBase64(file)
const formData = new FormData();
formData.append("blobFile", blob);
formData.append('blobFile', blob);
this.ChatSystemService.getDmRoom(roomId).send({
file: {
@@ -830,7 +841,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}],
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: fileBase64,
}
})
@@ -841,6 +852,18 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
_getBase64(file) {
return new Promise((resolve, reject)=>{
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
resolve(reader.result)
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
})
}
getFileReader(): FileReader {
const fileReader = new FileReader();
const zoneOriginalInstance = (fileReader as any)["__zone_symbol__originalInstance"];