public boolean uploadFile() throws IOException {
FileOutputStream fos=null;
FileInputStream fis=null;
try {
fos = new FileOutputStream(this.savePath+this.filePathFileName);
fis =new FileInputStream(this.filePath);
byte[] bytes=new byte[1024];
int real=fis.read(bytes);
while(real>0){
fos.write(bytes,0,real);
real=fis.read(bytes);
}
success=true;
// this.saveAttachFile();
} catch (FileNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().print("{success:flase,message:'失败'}");
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().print("{success:flase,message:'失败'}");
} finally {
//关闭输入流
fis.close();
//关闭输出流
fos.close();
}
System.out.println("上传文件名"+filePathFileName);
// System.out.println("上传文件类型"+myFileContentType);
// success = true;
return success;
}
/**
* 上传文件并添加上传记录
*
* @return 标示符
* @throws BusinessException
* 运行时异常
*/
public String saveAttachFile() throws IOException{
boolean stauts=uploadFile();
if(stauts){
Map<File, String> hashMap = new HashMap<File, String>();
hashMap.put(this.filePath, this.filePathFileName);
CommonAttachFile commonAttachFile = new CommonAttachFile();
commonAttachFile.setFileId(Long.valueOf(IDUtil.getNextSeqence()));
// commonAttachFile.setFileId(IDUtil.getNextLongID());
commonAttachFile.setFileName(this.filePathFileName);
try {
fileUploadCommonService.saveAttachFile(commonAttachFile, this, hashMap);
commonAttachFile = (CommonAttachFile)fileUploadCommonService.findObject(
PTIM_CA_SEARCHATTACHFILE, commonAttachFile.getFileId());
// 将已上传文件copy到摆渡用upload文件夹
fileUploadCommonService.copyAttachFile(commonAttachFile);
} catch (BusinessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().print("{error:true,message:'失败'}");
return null;
}
commonAttachFileList = new ArrayList<CommonAttachFile>();
success = true;
commonAttachFileList.add(commonAttachFile);
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().print("{success:true,fileName:'" + commonAttachFile.getFileName() + "'," +
"filePath:'" + commonAttachFile.getFilePath().replace("\\", "\\\\") + "',id:'" + commonAttachFile.getFileId() + "'}");
} else{
getResponse().setContentType("text/html;charset=utf-8");
getResponse().getWriter().print("{success:flase,message:'失败'}");
}
return null;
}记录1
最新推荐文章于 2025-05-26 01:29:32 发布
1万+

被折叠的 条评论
为什么被折叠?



