Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71530

Display image content as Base64 string?

$
0
0

@anta40 wrote:

Hi, this is my first time learning Ionic. I want to take picture, then convert it Base64 string so it can be sent via HTTP POST. Here’s my code:

import { Component } from '@angular/core';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { Dialogs } from '@ionic-native/dialogs/ngx';
import { File, FileEntry } from '@ionic-native/File/ngx';
import { FilePath } from '@ionic-native/file-path/ngx';
import { WebView } from '@ionic-native/ionic-webview/ngx';
import { Base64 } from '@ionic-native/base64/ngx';

@Component({
  selector: 'app-tab1',
  templateUrl: 'tab1.page.html',
  styleUrls: ['tab1.page.scss']
})

export class Tab1Page {

  constructor(private base64: Base64, private camera: Camera, private dialogs:Dialogs, private file:File, private filePath: FilePath, private webview:WebView) { }

  takePicture(){
    const options: CameraOptions = {
      quality: 50,
      destinationType: this.camera.DestinationType.FILE_URI,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE
    }
  
    this.camera.getPicture(options).then((imageData) => {

    this.base64.encodeFile(imageData).then((base64File: string) => {
      this.dialogs.alert(base64File)
    .then(() => console.log('Dialog dismissed'))
    .catch(e => console.log('Error displaying dialog', e));
    }, (err) => {
      console.log(err);
    });
    }, (err) => {
      console.log(err);
    });
  }
}

I don’t see any alert displaying the Base64 value of the image What’s wrong here?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71530

Trending Articles