![](/img/trans.png)
[英]how to validate the photo upload not greater than 1MB from javascript
[英]HTML5 Image load not working in firefox android for images with size greater than 1MB
我正在创建一个基于此https://demos.phplift.net/javascript-image-compress-using-html5-canvas-file-api/的图像预览和上传页面。 It is working fine in all web browsers and in android firefox (version 88.1.4) it is not working with images have size greater than 1MB, no issues in android chrome browser. 当我检查图像加载时(在代码中它是i.onload() ) function 没有触发 firefox 中的较大图像
html
<form id="upload_form">
<label for="file">Choose file</label>
<input type="file" id="fileinput" />
</form>
javascript function 是
<script>
var output_format = null;
var file_name = null;
function readFile(evt) {
var file = evt.target.files[0];
var reader = new FileReader();
reader.onload = function(event) {
var i = document.getElementById("source_image");
console.log(i);
i.src = event.target.result;
i.onload = function(){
console.log("Image loaded");
}
};
output_format = file.name.split(".").pop();
file_name = file.name;
console.log("Filename:" + file.name);
console.log("Fileformat:" + output_format);
console.log("Filesize:" + (parseInt(file.size) / 1024) + " Kb");
console.log("Type:" + file.type);
reader.readAsDataURL(file);
return false;
}
document.getElementById("fileinput").addEventListener("change", readFile, false);
</script>
有谁知道为什么大于 1 MB 的图像不会触发 firefox 中的图像加载?
不要使用 FileReader ......认为这可以工作:
i.src = URL.createObjectURL(file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.