This commit is contained in:
Eudes Inácio
2024-01-29 08:25:27 +01:00
parent 300b488174
commit ba464a4f73
8 changed files with 129 additions and 13 deletions
@@ -19,6 +19,7 @@ import { CMAPIService } from "src/app/shared/repository/CMAPI/cmapi.service";
import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
import { Filesystem, Directory, Encoding, FilesystemDirectory } from '@capacitor/filesystem';
import { Platform } from '@ionic/angular';
import { Capacitor } from '@capacitor/core';
enum ActionType {
newRapid = "1",
@@ -184,7 +185,8 @@ export class NewPublicationPage implements OnInit {
this.photoOrVideo = false;
let fileObject = {
FileBase64: picture,
FileExtension: this.removeTextBeforeSlash('jpeg', '/')
FileExtension: this.removeTextBeforeSlash('jpeg', '/'),
OriginalFileName: 'imagem'
}
const FileExtension = this.removeTextBeforeSlash('jpeg', '/')
@@ -228,7 +230,8 @@ export class NewPublicationPage implements OnInit {
).then((picture) => {
let fileObject = {
FileBase64: picture,
FileExtension: this.removeTextBeforeSlash('jpeg', '/')
FileExtension: this.removeTextBeforeSlash('jpeg', '/'),
OriginalFileName: 'image'
}
const FileExtension = this.removeTextBeforeSlash('jpeg', '/')
@@ -260,9 +263,22 @@ export class NewPublicationPage implements OnInit {
result.files.forEach(async blobFile => {
console.log(blobFile)
if (this.checkFileType.checkFileType(blobFile.mimeType) == 'image' || this.checkFileType.checkFileType(blobFile.mimeType) == 'video') {
console.log()
/* console.log('converte new way',this.getBase64(blobFile)) */
/* const blob = await fetch(
Capacitor.convertFileSrc(blobFile.path)
).then(r => r.blob()); */
/* console.log(await blob.arrayBuffer());
console.log("base64 :data:video/mp4;base64,",this.arrayBufferToBase64(await blob.arrayBuffer())) */
this.convertBlobToBase64(blobFile.blob).then((value) => {
console.log(value)
this.filesSizeSum = this.filesSizeSum + blobFile.size
if (this.fileSizeToMB(this.filesSizeSum) <= 20) {
@@ -290,6 +306,8 @@ export class NewPublicationPage implements OnInit {
this.httpErroHandle.validationMessagge('filessize');
}
}).catch((erro) => {
console.log(erro)
})
} else {
this.httpErroHandle.validationMessagge('filetype');
@@ -297,6 +315,9 @@ export class NewPublicationPage implements OnInit {
});
/* this.capturedImage = 'data:image/jpeg;base64,' +capturedImage.base64String;
this.capturedImageTitle = 'foto';
@@ -320,6 +341,49 @@ export class NewPublicationPage implements OnInit {
};
async loadVideoTablet() {
const result = await FilePicker.pickMedia
({
multiple: true,
});
console.log(result.files)
result.files.forEach(element => {
this.filesSizeSum = this.filesSizeSum + element.size
if (this.fileSizeToMB(this.filesSizeSum) <= 20) {
if (this.checkFileType.checkFileType(element.mimeType) == 'image' || this.checkFileType.checkFileType(element.mimeType) == 'video') {
let resultUrl = decodeURIComponent(element.path);
try {
Filesystem.readFile({ path: resultUrl })
.then(async (content) => {
console.log(result)
console.log(content)
this.filecontent = true;
let fileObject = new PublicationAttachmentEntity ({
base64: content.data,
extension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'video',
FileType: this.checkFileType.checkFileType( this.removeTextBeforeSlash(element.mimeType, '/'))
})
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
} catch (error) {
console.log('upload video error: ', error)
}
}
} else {
if (this.seletedContent.length === 0)
this.filesSizeSum = 0
this.httpErrorHandle.validationMessagge('filessize')
}
});
};
runValidation() {
this.validateFrom = true
@@ -551,9 +615,18 @@ export class NewPublicationPage implements OnInit {
resolve(reader.result)
}
reader.readAsDataURL(blob)
})
},)
}
getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
removeTextBeforeSlash(inputString, mark) {
if (inputString.includes(mark)) {
const parts = inputString.split(mark);
@@ -957,6 +1030,11 @@ export class NewPublicationPage implements OnInit {
if (!this.platform.is('desktop'))
return true;
}
checkDesktop() {
if (this.platform.is('desktop'))
return true;
}
}
// class UploadFileUseCase {