This commit is contained in:
ivan gomes
2021-11-17 08:39:17 +01:00
parent 14413b36f1
commit 17424217da
@@ -129,21 +129,21 @@ export class NewPublicationPage implements OnInit {
// toast.present();
// }
async selectImage() {
const image = await Camera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Uri,
source: CameraSource.Camera // Camera, Photos or Prompt!
});
// async selectImage() {
// const image = await Camera.getPhoto({
// quality: 90,
// allowEditing: false,
// resultType: CameraResultType.Uri,
// source: CameraSource.Camera // Camera, Photos or Prompt!
// });
if (image) {
this.saveImage(image)
}
}
// if (image) {
// this.saveImage(image)
// }
// }
// Create a new file from a capture image
async saveImage(photo: Photo) {
/* async saveImage(photo: Photo) {
const base64Data = await this.readAsBase64(photo);
const fileName = new Date().getTime() + '.jpeg';
@@ -156,25 +156,25 @@ async saveImage(photo: Photo) {
// Reload the file list
// Improve by only loading for the new image and unshifting array!
this.loadFiles();
}
} */
// https://ionicframework.com/docs/angular/your-first-app/3-saving-photos
private async readAsBase64(photo: Photo) {
if (this.platform.is('hybrid')) {
const file = await Filesystem.readFile({
path: photo.path
});
// private async readAsBase64(photo: Photo) {
// if (this.platform.is('hybrid')) {
// const file = await Filesystem.readFile({
// path: photo.path
// });
return file.data;
}
else {
// Fetch the photo, read as a blob, then convert to base64 format
const response = await fetch(photo.webPath);
const blob = await response.blob();
// return file.data;
// }
// else {
// // Fetch the photo, read as a blob, then convert to base64 format
// const response = await fetch(photo.webPath);
// const blob = await response.blob();
return await this.convertBlobToBase64(blob) as string;
}
}
// return await this.convertBlobToBase64(blob) as string;
// }
// }
// Helper function
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
@@ -506,49 +506,49 @@ private async savePicture(photo: Photo) {
// async selectImage() {
// const image = await Camera.getPhoto({
// quality: 90,
// allowEditing: false,
// resultType: CameraResultType.Uri,
// source: CameraSource.Photos // Camera, Photos or Prompt!
// });
async selectImage() {
const image = await Camera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Uri,
source: CameraSource.Photos // Camera, Photos or Prompt!
});
// if (image) {
// this.saveImage(image)
// }
// }
if (image) {
this.saveImage(image)
}
}
// // Create a new file from a capture image
// async saveImage(photo: Photo) {
// const base64Data = await this.readAsBase64(photo);
async saveImage(photo: Photo) {
const base64Data = await this.readAsBase64(photo);
// const fileName = new Date().getTime() + '.jpeg';
// const savedFile = await Filesystem.writeFile({
// path: `${IMAGE_DIR}/${fileName}`,
// data: base64Data,
// directory: Directory.Data
// });
const fileName = new Date().getTime() + '.jpeg';
const savedFile = await Filesystem.writeFile({
path: `${IMAGE_DIR}/${fileName}`,
data: base64Data,
directory: Directory.Data
});
// this.loadFiles();
// }
this.loadFiles();
}
// private async readAsBase64(photo: Photo) {
// if (this.platform.is('hybrid')) {
// const file = await Filesystem.readFile({
// path: photo.path
// });
private async readAsBase64(photo: Photo) {
if (this.platform.is('hybrid')) {
const file = await Filesystem.readFile({
path: photo.path
});
// return file.data;
// }
// else {
// // Fetch the photo, read as a blob, then convert to base64 format
// const response = await fetch(photo.webPath);
// const blob = await response.blob();
return file.data;
}
else {
// Fetch the photo, read as a blob, then convert to base64 format
const response = await fetch(photo.webPath);
const blob = await response.blob();
// return await this.convertBlobToBase64(blob) as string;
// }
// }
return await this.convertBlobToBase64(blob) as string;
}
}
async loadFiles() {
this.images = [];