JS代码
$(function() {
$('#file_upload').uploadifive({
'auto' : false,
'buttonClass': 'btn btn-primary',
'buttonText': "选择文件",
'queueID' : 'uploadqueue',
'uploadScript' : '/uploadfiles',
'onUploadComplete' : function(file, data) { console.log(data); }
});
});
后台代码
@RequestMapping("/uploadfiles")
@ResponseBody
public JSONArray uploadfiles(HttpServletRequest request) {
Calendar calendar=Calendar.getInstance();
List<String> filePathList = new ArrayList<String>();
// String filePath= SysConstant.UPLOADPATH;
String filePath = "C:";
// String filePathUrl=SysConstant.UPLOADPATHURL+"/"+calendar.get(Calendar.YEAR)+calendar.get(Calendar.MONTH);
String filePathUrl="C:/"+calendar.get(Calendar.YEAR)+calendar.get(Calendar.MONTH);
filePath=filePath+ File.separatorChar+calendar.get(Calendar.YEAR)+calendar.get(Calendar.MONTH);
try {
filePathList = FileUploadUtil.uploadFile(request, filePath,filePathUrl);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
if(filePathList.size() == 0){
//return "系统错误";
}
return null;
//return JSONArray.fromObject(filePathList);
FileUploadUtil
public class FileUploadUtil {
private static final Logger log = LoggerFactory.getLogger(FileUploadUtil.class);
public static List<String> uploadFile(HttpServletRequest request, String filePath, String filePathUrl) throws FileNotFoundException {
List<String> filePathList = new ArrayList<String>();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
String fileName = null;
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile mf = entity.getValue();
fileName = mf.getOriginalFilename();
String newfilepath = filePath + File.separatorChar + fileName;
//newfilepath = filePath + File.separatorChar + fileName;
System.out.println("newfilepath=" + newfilepath);
File dest = new File(filePath);
if (!dest.exists()) {
dest.mkdirs();
}
File uploadFile = new File(newfilepath);
if (uploadFile.exists()) {
uploadFile.delete();
}
try {
log.info("start upload file: " + fileName);
FileCopyUtils.copy(mf.getBytes(), uploadFile);
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
log.info("upload failed. filename: " + fileName + e.getMessage());
return null;
}
filePathList.add(filePathUrl+"/"+fileName);
}
return filePathList;
}
}
这份代码是从网上copy过来的, 当我选择 1.txt 2.txt 后点击上传文件.
设置debug后, 其中我看到控制台先打印一句
newfilepath=C:\20177\1.txt
之后才会进入debug读取2.txt.
求解为什么同样设置debug,第一份文件就进不去呢.