在javascript中使用什么测量单位来处理文件大小? [英] What measuring unit is used for file sizes in javascript?
本文介绍了在javascript中使用什么测量单位来处理文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在上传到服务器之前在客户端验证文件大小。但是我认为我需要在javascript中计算max-size。
am trying to validate file size on the client side before uploading to server. However I think i need to calculate max-size in javascript.
那么如何在javascript中编写 4MB ?
我还想知道基本上用什么测量单位来计算javascript的文件大小。
So how do i write 4MB in javascript ? I would also want to know basically in what measuring unit is javascript calculated in terms of file size.
下面是我的colde:
below is my colde:
//Grab the file list
var files = e.target.files;
$.each(files,function(i,file){
//check for the correct file extensiton
var n = file.name,
s = file.size
t = file.type;
if(s > 4MB){
console.log("File is greater than 4MB");
}
}
请帮忙。谢谢。
推荐答案
文件大小以字节为单位 - 请执行以下操作:
The file size is measured in bytes - do this:
if (s > 4 * 1024 * 1024)
alert("Too big");
这篇关于在javascript中使用什么测量单位来处理文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文