How do I properly configure photo file to match format of html input.files with Cordova Camera?

后端 未结 1 998
终归单人心
终归单人心 2021-01-26 03:13

I have an existing web service that handles user input of a photo (as well as some other number and text data). The photo is captured via the input tag:



        
相关标签:
1条回答
  • 2021-01-26 04:02

    Turns out it was a simple fix:

    navigator.camera.getPicture(
        function(imgData) {
            var fd = new FormData();
            var reader;
            var imgBlob;
            window.resolveLocalFileSystemURL(imgData, function(fileEntry) {
                fileEntry.file(function(file) {
                    reader = new FileReader();
                        reader.onloadend = function(e) {
                            imgBlob = new Blob([ this.result ], { type: "image/jpeg" } );
                            window.__file = imgBlob; // PLACE THE FILE ASSIGNMENT HERE AFTER THE READER HAS INGESTED THE FILE BYTES
                        };
                        reader.readAsArrayBuffer(file);
                        // window.__file = imgBlob; // FILE ASSIGNMENT USED TO BE HERE
                 }, function(e){
                    console.log('error with photo file');
                 });
            }, function(e){
                console.log('error with photo file');
            });
        },
        function() {
            alert('Error taking picture', 'Error');
        },
        options);
    };
    
    0 讨论(0)
提交回复
热议问题