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/ ...
随机推荐
- 不借助工具在浏览器中通过Web API执行Dynamics 365操作(Action)实例
摘要: 本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复262或者20170727可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyon ...
- Python学习记录----类型匹配(转)
import types aaa = 0 print type(aaa) if type(aaa) is types.IntType: print "the type of aaa is i ...
- Storm源码阅读之SpoutOutputCollector
不得不说storm是一个特别棒的实时计算框架.为了对后文理解的方便,先说几个storm中的术语: Topology:拓扑图或者拓扑结构.在storm中它通过消息分组的分式连接Spout和Bolt节点定 ...
- hive配置过程中出现的一个问题
执行hive里面的insert语句的时候,报错,执行失败查看hadoop的日志文件之后发现错误的详细信息如下: 把hdfs-site.xml中的hadoop.tmp.dir这个属性添加到core-si ...
- 内核对象kobject和sysfs(1)——概述
内核对象kobject和sysfs(1)--概述 问题: 在走读驱动代码时,经常看见kref,kobj,sysfs这些结构,这些结构到底有什么作用?如何理解并使用这些结构呢?这将在接下来的这一系列文章 ...
- OpenCV1.0在VC ++6.0下的配置
1.本人使用win7操作系统,首先要预装VC++6.0,安装方法不再赘述. 2.在OpenCV官方网站下载OpenCV的安装文件"OpenCV_1.0.EXE"(参考链接:http ...
- 办公楼[POI2007]
题目描述 FGD开办了一家电话公司.他雇用了N个职员,给了每个职员一部手机.每个职员的手机里都存储有一些同事的电话号码.由于FGD的公司规模不断扩大,旧的办公楼已经显得十分狭窄,FGD决定将公司迁至一 ...
- Lettuce_webdriver 自动化测试
这篇文章主要讲解以下几点: 1. Lettuce_webdriver环境搭建 2. lettuce_webdriver自动化实例讲解 一. lettuce_webdriver环境搭建 搭建lettuc ...
- NYOJ--65--另一种阶乘问题
/* Name: NYOJ--65--另一种阶乘问题 Date: 17/04/17 16:35 Description: 去年刚开始做题时的代码看不下去了,再做,打表呗 */ #include< ...
- 初笔,JAVA.HelloWorld代码详解
HelloWorld.java //文件名 public class HelloWorld{ public static void main(String[] args){ System.out.pr ...