mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix chat
This commit is contained in:
@@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -715,12 +714,11 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
resultType: CameraResultType.Base64,
|
||||
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);
|
||||
@@ -738,22 +736,39 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
"title_link_download": false,
|
||||
}],
|
||||
attachmentsModelData: {
|
||||
fileBase64: await this.fileService.blobToBase64(blob),
|
||||
fileBase64: imageBase64,
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -763,13 +778,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,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -837,14 +852,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);
|
||||
@@ -862,7 +876,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
"title_link_download": false,
|
||||
}],
|
||||
attachmentsModelData: {
|
||||
fileBase64: await this.fileService.blobToBase64(blob),
|
||||
fileBase64: imageBase64,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -874,6 +888,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") {
|
||||
@@ -884,8 +899,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: {
|
||||
@@ -901,7 +918,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}],
|
||||
temporaryData: formData,
|
||||
attachmentsModelData: {
|
||||
fileBase64: await this.fileService.blobToBase64(blob),
|
||||
fileBase64: fileBase64,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1123,5 +1140,45 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
} else { }
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
};
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user