Using form input to access camera and immediately upload photos using web app

后端 未结 1 548
眼角桃花
眼角桃花 2020-12-04 05:10

I came across this answer which is brilliant:

In iPhone iOS6 and from Android ICS onwards, HTML5 has the following tag which allows you to take pict

相关标签:
1条回答
  • 2020-12-04 05:36

    It's really easy to do this, simply send the file via an XHR request inside of the file input's onchange handler.

    <input id="myFileInput" type="file" accept="image/*;capture=camera">
    
    var myInput = document.getElementById('myFileInput');
    
    function sendPic() {
        var file = myInput.files[0];
    
        // Send file here either by adding it to a `FormData` object 
        // and sending that via XHR, or by simply passing the file into 
        // the `send` method of an XHR instance.
    }
    
    myInput.addEventListener('change', sendPic, false);
    
    0 讨论(0)
提交回复
热议问题