profile picture done

This commit is contained in:
Eudes Inácio
2023-08-29 16:05:32 +01:00
64 changed files with 519 additions and 289 deletions
@@ -435,15 +435,14 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
this.audioRecorded = recordData?.value?.recordDataBase64;
}
else if(recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
else if (recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`;
}
//Converting base64 to blob
const encodedData = btoa(this.audioRecorded);
const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType)
const formData = new FormData();
formData.append("blobFile", blob);
@@ -460,7 +459,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}],
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: encodedData,
}
})
@@ -748,22 +747,39 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"title_link_download": false,
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: base64,
}
})
}
async takePicture() {
// 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 blob = await base64.blob();
// const formData = new FormData();
// formData.append("blobFile", blob);
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 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 base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
@@ -773,13 +789,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"guid": ''
},
attachments: [{
"title": capturedImageTitle,
"title": 'file.jpg',
"text": "description",
"title_link_download": false,
}],
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: imageBase64,
}
})
@@ -847,14 +863,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Base64,
source: CameraSource.Photos
source: CameraSource.Camera
});
//const imageData = await this.fileToBase64Service.convert(file)
//
const response = await fetch('data:image/jpeg;base64,' + file.base64String!);
const blob = await response.blob();
const imageBase64 = 'data:image/jpeg;base64,' + file.base64String
const blob = this.dataURItoBlob(imageBase64)
console.log(imageBase64)
const formData = new FormData();
formData.append("blobFile", blob);
@@ -872,7 +887,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"title_link_download": false,
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: imageBase64,
}
})
@@ -884,6 +899,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
const roomId = this.roomId
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") {
@@ -894,8 +910,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
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.getGroupRoom(roomId).send({
file: {
@@ -911,7 +929,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}],
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
fileBase64: fileBase64,
}
})
@@ -1170,5 +1188,45 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
}
dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
// create a view into the buffer
var ia = new Uint8Array(ab);
// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], {type: mimeString});
return blob;
}
_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);
};
})
}
}