Ionic - Profile Image Upload (Mobile / Deskptop)


#1

Hi,

How can i intuitively switch between uploading a profile image on a mobile and also a desktop.

If the user is on a mobile i can use the native camera object. However, if i there using browser what can i use to allow user to pic a file from there dekstop.

Also, is it better to save image as base64image or blob?

  presentActionSheet() {
        let actionSheet = this.actionSheetCtrl.create({
            title: 'Select Image Source',
            buttons: [
                {
                    text: 'Load from library',
                    handler: () => {                        this.takeImage(this.camera.PictureSourceType.PHOTOLIBRARY);
                    }
                },
                {
                    text: 'Cancel',
                    role: 'cancel',
                }
            ]
        });
        actionSheet.present();
    }

    takeImage(sourceType) {

        const options: CameraOptions = {
            quality: 100,
            sourceType: sourceType,
            saveToPhotoAlbum: false,
            correctOrientation: true
        };


        this.camera.getPicture(options).then((imageData) => {

            let base64Image = 'data:image/jpeg;base64,' + imageData;
storeImage(base64Image)

        }, (err) => {
            this.presentToast(err);
        });
    }

#2

@KKHAN
Did you get any solution to pick image from dekstop using ionic?


#3

This works for me: