* @param maxFileSize
* @return
* @throws Exception
*/
public Data uploadFiles(HttpServletRequest request, String path, long dirId) throws Exception {
Data list = new Data();
int index = 0;
MultipartHttpServletRequest mptRequest = (MultipartHttpServletRequest) request;
Iterator fileIter = mptRequest.getFileNames();
while (fileIter.hasNext()) {
MultipartFile mFile = mptRequest.getFile((String) fileIter.next());
String tmp = mFile.getOriginalFilename();
if (tmp.lastIndexOf("\\") >= 0) {
tmp = tmp.substring(tmp.lastIndexOf("\\") + 1);
}
list.add(index,FILE_NAME, tmp);
list.add(index,FILE_PHY_NAME, getPhysicalFileName());
if( tmp.lastIndexOf(".") < 0 ) {
list.add(index,EXTENTION, "");
} else {
String ext = tmp.substring(tmp.lastIndexOf(".") + 1);
if( ext.length() > 5) {
ext = ext.substring(0, 5);
}
list.add(index,EXTENTION, ext);
}
list.add(index,FILE_SIZE, mFile.getSize());
list.add(index,DIR_ID, dirId);
if (tmp.lastIndexOf(".") >= 0) {
String phyName = list.getString(index, FILE_PHY_NAME) + tmp.substring(tmp.lastIndexOf("."));
list.add(index,FILE_PHY_NAME, phyName);
}
String filePath = properties.getProperty("baseDir").replaceAll("\\\\", "/") + SEPERATOR + path + SEPERATOR + list.getString(index, FILE_PHY_NAME);
filePath = filePath.replaceAll("\\\\", "/");
if (mFile.getSize() > 0) {
mFile.transferTo( new File(filePath) );
}
if(filter(list.getString(index, EXTENTION))) {
index++;
list.remove(index);
} else {
File removed = new File(filePath);
removed.delete();
removed = null;
}