PWA - Cordova-camera-plugin

I am trying to figure out what’s the alternative to the camera plugin when app is running in the browser.
Ideally, it would be good to pick photos from the download folder or an image URL.

Anyone has worked on this?

ng2-file-upload let’s you browse for files and accepts drag & drop.
ng2-file-upload

2 Likes

Thanks for the link.

I was looking at html5 <input type="file"> and was able to get the image file from it. This is the code:

HTML

    <h2>Upload Picture</h2>
    <input type="file" (ngModelChange)="browsePhotoBrowser($event)" accept="image/*">

TS

    constructor() {}

    browsePhotoBrowser(event) {

        let reader = new FileReader();

        let input: any = document.querySelector('input[type=file]')  //Type 'any' to prevent this error: `Property files does not exist on type 'HTMLElement'`
        let selectedFile = input.files[0];

        console.log("event", event);
        console.log("selectedFile", selectedFile);

        reader.onloadend = () => {
		    console.log("reader.result", reader.result);
        };

        reader.readAsDataURL(selectedFile);
    }

I just added code to a previous post that uses ng2-file-upload.
This may not be the most elegant way to do this but it is working for me.
PWA approach to uploading files