什么是“允许的类型”? struts2 中的 .rar 文件(拦截器“fileUpload”)?
<package name="my-default" extends="struts-default" namespace="/">
<interceptors>
<interceptor-stack name="globalInterceptor">
.....
<interceptor-ref name="fileUpload">
<param name="maximumSize">1048576</param>
<param name="allowedTypes">application/x-rar-compressed</param>
</interceptor-ref>
.....
</interceptor-stack>
</interceptors>
....
</struts>
我想在 struts2 中挖掘 .rar 文件的类型,该文件拦截器“fileUpload”,但是当我定义“allowedTypes”时,“ application/x-rar-compressed”,它不起作用。
我该如何解决这个问题?
<package name="my-default" extends="struts-default" namespace="/">
<interceptors>
<interceptor-stack name="globalInterceptor">
.....
<interceptor-ref name="fileUpload">
<param name="maximumSize">1048576</param>
<param name="allowedTypes">application/x-rar-compressed</param>
</interceptor-ref>
.....
</interceptor-stack>
</interceptors>
....
</struts>
I want to mine type for .rar file in struts2 which interceptor "fileUpload", but when I define "allowedTypes" which "application/x-rar-compressed", It doesn't work.
How can I resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些是允许的类型值 -
image/gif、image/jpeg、image/png、image/bmp、application/msword、text/plain、application/pdf、application/ms-excel、application/vnd.ms-excel、image /bitmap
Rar 和 zip 不是其中之一。
These are the allowed type values -
image/gif,image/jpeg,image/png,image/bmp,application/msword,text/plain,application/pdf,application/ms-excel,application/vnd.ms-excel,image/bitmap
Rar and zip are not one of them.
MIME 类型由您的浏览器设置,并且这一点(特别是对于 .rar 文件类型,不像其他文件类型那么流行)并不完全可预见 - 我怀疑它可能因浏览器而异。如果想安全起见,您可以省略 allowedTypes 选项并在操作中以编程方式进行检查。也许您还希望(不是作为替代,而是作为补充检查)使用 Javascript 检查客户端的文件扩展名。
The MIME type is set by your browser, and this (specially for a .rar file type, not so popular as others) is not fully previsible - I suspect it can vary from browser to browser. If want to play safe, you can omit the allowedTypes option and do the check programatically in your action. Perhaps you'll want also (not as an alternative, but as an complementary check) to check the file extension in the client side, with Javascript.
尝试
rar
try
<param name="allowedExtensions ">rar</param>