检查上传文件的大小
source link: https://www.itwork.club/2020/12/18/check-file-size/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
检查上传文件的大小
Dec 18, 2020JavaScript6点击
我们可以通过 js 检查用户上传的文件是否过大
通过 file 类型的 input 可以得到用户上传的文件,也就是一个 File 对象
通常情况下, File 对象是来自用户在一个 元素上选择文件后返回的 FileList 对象,也可以是来自由拖放操作生成的 DataTransfer 对象,或者来自 HTMLCanvasElement 上的 mozGetAsFile() API。在Gecko中,特权代码可以创建代表任何本地文件的File对象,而无需用户交互(有关详细信息,请参阅 注意事项 。
file 有一个 size 属性
以字节为单位返回文件的大小。
检查文件是否过大,可以写成
1
2
3
4
5
6
7
export const checkFileSizeTooLarge = (file, limitSize) => {
if (!(file instanceof File)) {
throw new Error('Not a file')
}
const size = Math.round(file.size / 1024)
return size > limitSize
}
原文作者: dgb8901,yinxing
原文链接: https://www.itwork.club/2020/12/18/check-file-size/
版权声明: 转载请注明出处
体验小程序「简易记账」
关注公众号「特想学英语」
Recommend
-
24
下面的讨论基于的假定: 可以单独处理一行数据,行间数 据相关性为零。 方法一: 仅使用 Python 内置模板,逐行读取到内存。 使用 yield,好处是解...
-
30
-
5
linux下c语言编程,获取超大文件大小(size超过2GB) 发表于 2018-06-11 11:06...
-
13
您现在的位置:首页 --> 系统运维 --> 根据文件大小删除一个特殊文件名的文件 根据文件大小删除一...
-
8
WordPress上传文件大小限制修改 最后更新 : 2020.01.30 WordPress上传媒体文件默认大小限制是2M...
-
7
Linux 下按照文件大小查找文件 Apr 20th, 2020 为什么需要这篇文章 我想大概是这种情况,你的Linux 机器下磁盘满了,需要清理,然后就需要查找大的文件,确定是否有用进行删除。 查找500M以上的文件
-
8
sword群晖修改Cloud Sync上传OneDrive单文件15GB大小限制前言Cloud Sync可以使群晖轻松连接到公共云服务,如百度云、Dropbox、Google Cloud Sto...扫描右侧二维码阅读全文282021/06...
-
1
windows2008 iis7 phpmyadmin上传文件大小限制 2015年7月2日 由 admin 留言 » 第一步:修改php.ini配置文件中文件上传大小...
-
3
【笔记】SpringBoot配置文件上传大小 2022-07-29 1...
-
5
iview实现文件上传 限制上传格式、大小 精选 原创 问题描述:下面以CRMEB Pro版产品为例1.当上传的文件...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK