exjs上传图片异常:com.jspsmart.upload.SmartUploadException: File can't be saved (1120).
错误:
文件名格式不对:未命??.jpg
SmartUpload mySmartUpload = new SmartUpload();
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
myFileName = new String(myFile.getFileName().getBytes("gbk"),"utf-8");
寻找原因历程:
1、尝试了上传几个不同的文件,发现文件名%2==0的时候,文件名不会出现最后一个中文变成??的情况
猜想是编码格式的问题:于是包括jsp,js,request,response的编码格式统统都设置为utf-8。后来发现还是没有任何效果。
猜想可能是ext的FormPanel组建的原因。
2、在js界面获取FormPanel的绝对路径:Ext.getCmp('loadfile').getValue();(loadfile是组建FormPanel的id)没有出现乱码
原因那应该就是JSPSmart这个jar包本身的bug了。
解决方法:
1. 在servlet将上传文件进行重命名,这样就可以避免文件名乱码的问题。但是有些情况是必须使用原来的文件名的,这个方法就无法解决文艺了。
2. 对SmartUpload进行反编译,修改代码。这个百度上很多。
3. 据说这个是SmartUpload的一个Bug,所以可以关注官网更新jar包。不过如果其他同事也用这个jar,不知道升级后会他们会不会有影响,所以他们不给我升级。
虽然姐觉得一般升级不会对原来的版本影响的,难道使用jdk7会造成jdk2的影响?
4. 据说这个SmartUpload在上传大文件类型的时候也有bug,建议使用Commons FileUpload
5. 在前端页面也就是ext的FormPanel summit的时候截取文件名作为参数传递到后台,后台就不需要用SmartUpload本身的方法去获取文件名,这样可以避免文件名的乱码。
@ js端截取文件名并通过url传参到后台:
var urlStr = Ext.getCmp('loadfile').getValue();
var fileName = urlStr.substring(urlStr.lastIndexOf("\\")+1,urlStr.lastIndexOf("."));
form.form.submit({
url : '/AdjustServlet?action=upload&slid='+slid+'&fileName='+fileName,
method : 'POST',
waitMsg: '正在上传...',
success : function() {
//list();
Ext.Msg.alert('Message','上传成功!');
win.close();
},
failure : function() {
Ext.Msg.alert('Error','上传失败.');
}
});
@ 后台接收文件名并且用方法获取后缀名,扩展名=文件名+"."+后缀名
String fileName = new String(request.getParameter("fileName").getBytes("iso-8859-1"),"utf-8");
String suffix = myFile.getFileExt();
myFileName.append(fileName).append(".").append(suffix);
这个方法就可以解决文件名中文为基数位乱码了。
exjs上传图片异常:com.jspsmart.upload.SmartUploadException: File can't be saved (1120).的更多相关文章
- How to upload a file in MVC4
Uploading a file in Asp.Net MVC application is very easy. The posted file is automatically available ...
- axios upload excel file
axios upload excel file https://github.com/axios/axios/issues/1660 https://stackoverflow.com/questio ...
- fetch & form-data & upload & image file
fetch & form-data & upload & image file no need multipart/form-data https://blog.xinshan ...
- 上传图片预览JS脚本 Input file图片预览的实现示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jquery ajax发送delete(use in jquery file upload delete file)
环境: jQuery file upload HTML example code <div class="pic-preview"> <div class=&qu ...
- [MODx] Solve cannot upload large file
If you also run into this problem, dont' worry, here is the solution for you. First: In Modx, go &qu ...
- iOS上传图片和视频(base64和file)
前言:iOS开发中经常会使用到图片和视频上传及保存到相册,下面我讲介绍视频图片的两种上传服务器的方法.以阿里云的OSS服务器为例. 友情提示:上传图片方法在APP中使用很广泛,最好单独写一个图片上传的 ...
- Upload a file with $.ajax to AWS S3 with a pre-signed url
转载自:https://gist.github.com/guumaster/9f18204aca2bd6c71a24 生成预签名的Demo文档:https://docs.aws.amazon.com/ ...
- troubleshooting-执行导数shell脚本抛异常error=2, No such file or directory
Cannot run program "order_log.sh" (in directory "/data/yarn/nm/usercache/chenweidong/ ...
随机推荐
- [js] 实现接口
摘要 js 语言并没有interface implement 关键字,如果要做到和后端语言类似的接口,一般会需要模拟实现. 在oo 编程中, 接口可以让架构师规定好模块必须要实现的方法, 尽量解耦模块 ...
- 【Django】学习资料
一.基础 http://www.ibm.com/developerworks/cn/linux/l-django/ 安装.数据库连接.url路由转发 http://djangobook.py3k.cn ...
- mysql的并发处理机制_上篇
回来写博客,少年前端时间被django迷了心魄 如果转载,请注明博文来源: www.cnblogs.com/xinysu/ ,版权归 博客园 苏家小萝卜 所 ...
- 坏块管理(Bad Block Management,BBM)
看了很多坏块管理的文章,加上自己的理解,把整个坏块管理做了个总结. 坏块分类 1.出厂坏块 又叫初始坏块,厂商会给点最小有效块值(NVB,mininum number of valid blocks) ...
- Python爬虫番外篇之关于登录
常见的登录方式有以下两种: 查看登录页面,csrf,cookie;授权:cookie 直接发送post请求,获取cookie 上面只是简单的描述,下面是详细的针对两种登录方式的时候爬虫的处理方法 第一 ...
- javascript基础知识2#数据类型
数据类型 typeof 操作符 undefined类型 boolean类型 Nubmer类型 NaN(not a number) 数值转换parseInt,parseFloat String类型 字符 ...
- Tornado 判断用户登录状态和操作权限(装饰器)
判断是否登录: def authenticated(method): '''''' @functools.wraps(method) def wrapper(self, *args, **kwargs ...
- Code Complete
一.<代码大全>优先阅读参考顺序: 自学编程人:第07章 高质量的子程序 低年级学生:第11章 变量命名的力量 高年级学生:第08章 防御式编程 初级程序员:第18章 表驱动法 高级程序员 ...
- <经验杂谈>C#生成条形码
虽然二维码满天飞,但也不能忘了条形码,本篇介绍可以在C#中使用的1D/2D编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码: 条形码的标准: 条形码的标准有ENA条形码.U ...
- MacOS下安装gdb、mgo
安装gdb:http://blog.panks.me/posts/2013/11/install-gdb-on-os-x-mavericks-from-source/ 注意最后两步: killall ...