使用 HTML5 为移动设备捕获的图像 [英] captured images with HTML5 for mobile devices
问题描述
我正在使用 html 5 <input type="file" accept="image/*;capture=camera"/>
用于网络移动设备的文件元素拍照它工作正常,但我如何处理 file.value 以将其发送到网络服务或数据库?这是移动设备的演示 演示链接
i am using html 5 <input type="file" accept="image/*;capture=camera"/>
file element for web mobile
to take photo it works fine but how can i handle file.value to send it to web service or database?
here is demo for mobile devices Demo link
这是我的代码但不起作用我无法获取文件上传值
here is my code but does not work i can not get file upload value
<html>
<script>
function getPhoto()
{
alert('2');
var fu1 = document.getElementById("myfile").value;
alert("You selected " + fu1);
}
</script>
<body>
<form>
<input type="file" name="myfile" accept="image/*;capture=camera"/>
<input type="submit"/>
<input type="button" value="get Photo path" onclick="getPhoto()">
</form>
</body>
</html>
推荐答案
您需要使用文件 API:http://www.w3.org/TR/FileAPI/
You need to use the File API: http://www.w3.org/TR/FileAPI/
这是来自 html5rocks.com 的一个不错的教程:http://www.html5rocks.com/en/tutorials/file/dndfiles/
Here is a nice tutorial from html5rocks.com: http://www.html5rocks.com/en/tutorials/file/dndfiles/
尝试做这样的事情
HTML
<input type="file" id="myfile" name="myfile" accept="image/*;capture=camera"/>
JS
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object, files[0] is your file
}
document.getElementById('file').addEventListener('change', handleFileSelect, false);
如果需要在JS中读取文件,则需要使用FileReader API.
If you need to read the file in JS, then you need to use the FileReader API.
这篇关于使用 HTML5 为移动设备捕获的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!