jQuery的文件上传内容类型/扩展验证 [英] jQuery-File-Upload content type/extension validation

查看:211
本文介绍了jQuery的文件上传内容类型/扩展验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery-File-Upload与rails 3,它工作得很好。但是我没有发现如何在客户端验证上传文件的扩展名或内容类型。



有没有办法做到这一点?



因为我会在server-sid用Paperclip来验证它,但是我认为最好在客户端验证一次。 b $ b

解决方案

acceptFileTypes



允许的文件类型的正则表达式,文件名,因为只有支持File API的浏览器报告文件类型。



$ p $ 类型:正则表达式
示例: /(\.|\/)(gif|jpe?g|png)$/i

请参阅 https://github.com/blueimp/jQuery-File-Upload/wiki /选项


I am using jQuery-File-Upload with rails 3, it works very well. But I didn't find anything about how to validate the extension or the content type of the upload file on the client-side.

Is there a way to do that?

Of cause I will anyway validate it by Paperclip at server-sid, but I think it would be better to validate it once at client-side.

解决方案

acceptFileTypes

The regular expression for allowed file types, matches against either file type or file name as only browsers with support for the File API report the file type.

Type: Regular Expression
Example: /(\.|\/)(gif|jpe?g|png)$/i

See https://github.com/blueimp/jQuery-File-Upload/wiki/Options

这篇关于jQuery的文件上传内容类型/扩展验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆