mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
bug adding file to chat on ios solved
This commit is contained in:
@@ -34,6 +34,7 @@ import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { RouteService } from 'src/app/services/route.service';
|
||||
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
||||
import { sanitize } from "sanitize-filename-ts";
|
||||
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -828,8 +829,47 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
async addFileToChat(types: typeof FileType[]) {
|
||||
|
||||
|
||||
|
||||
const roomId = this.roomId
|
||||
|
||||
if(this.platform.is('ios')) {
|
||||
console.log('ios add file ')
|
||||
|
||||
const resultt = await FilePicker.pickFiles({
|
||||
types: ['application/pdf'],
|
||||
multiple: false,
|
||||
readData: true,
|
||||
});
|
||||
|
||||
console.log('RESULT', resultt.files[0])
|
||||
|
||||
const blobb = this.fileService.base64toBlob(resultt.files[0].data, resultt.files[0].mimeType)
|
||||
|
||||
const formDataa = new FormData();
|
||||
formDataa.append('blobFile', blobb);
|
||||
/* console.log('add file', fileBase64) */
|
||||
|
||||
this.ChatSystemService.getGroupRoom(roomId).send({
|
||||
file: {
|
||||
"type": resultt.files[0].mimeType,
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": sanitize(resultt.files[0].name),
|
||||
"name": sanitize(resultt.files[0].name),
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formDataa,
|
||||
attachmentsModelData: {
|
||||
fileBase64: '',
|
||||
}
|
||||
})
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import { NotificationsService } from 'src/app/services/notifications.service';
|
||||
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'
|
||||
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
||||
import { sanitize } from "sanitize-filename-ts";
|
||||
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
||||
|
||||
|
||||
|
||||
@@ -839,9 +840,46 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
async addFileToChat(types: typeof FileType[]) {
|
||||
console.log('add file')
|
||||
console.log('add file ')
|
||||
const roomId = this.roomId
|
||||
|
||||
if(this.platform.is('ios')) {
|
||||
console.log('ios add file ')
|
||||
|
||||
const resultt = await FilePicker.pickFiles({
|
||||
types: ['application/pdf'],
|
||||
multiple: false,
|
||||
readData: true,
|
||||
});
|
||||
|
||||
console.log('RESULT', resultt.files[0])
|
||||
|
||||
const blobb = this.fileService.base64toBlob(resultt.files[0].data, resultt.files[0].mimeType)
|
||||
|
||||
const formDataa = new FormData();
|
||||
formDataa.append('blobFile', blobb);
|
||||
/* console.log('add file', fileBase64) */
|
||||
|
||||
this.ChatSystemService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": resultt.files[0].mimeType,
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": sanitize(resultt.files[0].name),
|
||||
"name": sanitize(resultt.files[0].name),
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formDataa,
|
||||
attachmentsModelData: {
|
||||
fileBase64: '',
|
||||
}
|
||||
})
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
console.log(file)
|
||||
|
||||
@@ -1239,6 +1277,17 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
dataURItoBlobIso(dataURI: any) {
|
||||
const byteString = window.atob(dataURI);
|
||||
const arrayBuffer = new ArrayBuffer(byteString.length);
|
||||
const int8Array = new Uint8Array(arrayBuffer);
|
||||
for (let i = 0; i < byteString.length; i++) {
|
||||
int8Array[i] = byteString.charCodeAt(i);
|
||||
}
|
||||
const blob = new Blob([int8Array], { type: 'application/pdf' });
|
||||
return blob;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user