protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
SessionParams sessionParams = (SessionParams) VSessionUtils.getSessionParams(request);
UserLogin userLogin = sessionParams.getUserInfo();
UserConfig userConfig = sessionParams.getCustoms();
FileInfo fileInfo = new FileInfo();
String fileName = "";
String orgFileName = "";
String bucket="";
if(null!=userLogin && null!=userLogin.getWebFile()){
bucket= userLogin.getWebFile().getBucketName();
}
String fileUrl = "";
String vId = "";
String wId = "";
WebCastServiceImpl webcastService=BeanUtils.getBean(WebCastServiceImpl.class);
// 创建缓冲区
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
FileItemIterator fileItem = null;
InputStream in=null;
try{
List<FileItem> items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
// String name = item.getFieldName();
if(item.isFormField()){//判断是否是文件流
String name = item.getFieldName();
String value = item.getString();
if(name.equals("wId")){
wId=item.getString();
}
}
if(!item.isFormField() && item.getName().length() > 0){
fileName = item.getName();//会将完整路径名传过来
/*int start = value.lastIndexOf("\");
fileName = value.substring(start+1);*/
if(fileName.indexOf("\") > 0){
String[] tempArr = fileName.split("\\");
fileName = tempArr[tempArr.length -1];
}
fileInfo.setFilename(fileName);
fileInfo.setFiletype(this.getExtension(fileName));
fileInfo.setFilename(getFileUrl(fileName,fileInfo.getFiletype()));
orgFileName = fileName;
if(!fileInfo.getFiletype().equals("mp4")){
response.sendRedirect("/worklite/webcast/open/uploadTemp?success=type&vId=&fileName=");
return;
}
if(null!=fileName && !fileName.equals("")){
UUID uuid = UUID.randomUUID();
fileName = uuid.toString()+"."+fileInfo.getFiletype();
fileInfo.setFilename(fileName);
}
in = item.getInputStream();
//item.write(new File(realPath,fileName));
}
}
WebCast_baseinfo base=webcastService.getWebCast(wId);
LocalFileManager fileMgr = new LocalFileManager();
fileUrl = fileMgr.recvFromStream(FileConstants.TYPE_MEDIA, FileConstants.SUBTYPE_VIDEO, fileInfo.getFilename(), in);
vId=UploadVideo.upload(fileMgr.getServerFileURL(FileConstants.TYPE_MEDIA, FileConstants.SUBTYPE_VIDEO,fileName), base.getCompanyId()+"_"+base.getwName()+"_"+orgFileName);
WebCast_upvideo upvideo=webcastService.getWebcastUploadVideo(wId);
try{
if(null!=upvideo){
webcastService.uptWebcastUploadVideo(wId,vId);
}else{
webcastService.addWebcastUploadVideo(wId,vId,new Date());
}
}catch(Exception e){
Log.error(e.getMessage());
response.sendRedirect("/worklite/webcast/open/uploadTemp?success=false&vId=&fileName=");
}
response.sendRedirect("/worklite/webcast/open/uploadTemp?success=true&vId="+vId+"&fileName="+orgFileName);
}catch(Exception e){
Log.error(e.getMessage());
response.sendRedirect("/worklite/webcast/open/uploadTemp?success=false&vId=&fileName=");
}
}