我想用 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
我发现“类型”属性是空的。它发生在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>