我想用html上传图片,但总是失败。我通过console.log检查它,它会生成以下消息。
07-31 19:09:07.071: I/Web Console(16417): size:66797 at file:///android_asset/www/index.html:18
07-31 19:09:07.091: I/Web Console(16417): lastModifiedDate:Tue Jul 30 2013 03:44:18 GMT+0700 (WIT) at file:///android_asset/www/index.html:18
07-31 19:09:07.101: I/Web Console(16417): fileSize:66797 at file:///android_asset/www/index.html:18
07-31 19:09:07.111: I/Web Console(16417): name:1375130658314.jpg at file:///android_asset/www/index.html:18
07-31 19:09:07.121: I/Web Console(16417): type: at file:///android_asset/www/index.html:18
07-31 19:09:07.121: I/Web Console(16417): fileName:1375130658314.jpg at file:///android_asset/www/index.html:18
07-31 19:09:07.121: I/Web Console(16417): webkitSlice:function webkitSlice() { [native code] } at file:///android_asset/www/index.html:18
我发现“type”属性为空。它发生在android 4.0.4。
但在4.1.2和4.1.3上没问题。
这个问题有什么线索吗?
-
<!doctype html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>Image preview example</title>
<script type="text/javascript">
oFReader = new FileReader(),
rFilter = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/x\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\/x\-xwindowdump)$/i;
oFReader.onload = function (oFREvent) {
document.getElementById('preview').src = oFREvent.target.result;
};
function loadImageFile() {
if (document.getElementById("uploadImage").files.length === 0) { return; }
var oFile = document.getElementById("uploadImage").files[0];
for(var x in oFile)
console.log(x+":"+oFile[x]);
oFReader.readAsDataURL(oFile);
}
</script>
</head>
<body >
<form name="uploadForm">
<table>
<tbody>
<tr>
<img id="preview" style="width: 100px; height: 100px;" src="" alt="Image preview" />
<td><input id="uploadImage" type="file" name="myPhoto" onchange="loadImageFile()" /></td>
</tr>
</tbody>
</table>
<p><input type="submit" value="Send" /></p>
</form>
</body>
</html>
答案 0 :(得分:0)
<input type="file" name="photo" accept="image/*" capture="camera">
从这里得到它:Does the android web browser allow uploading photos just taken from camera?
有(有?)问题:https://code.google.com/p/android/issues/detail?id=2519
我尝试了一次基于PhoneGap for Android的应用程序,但没有让它工作(虽然没有尝试上面的html行。我在互联网上发现当时不可能(是关于上传图片以用作应用和网站中的头像。)