uploadify 파일 업로드 사용
18932 단어 uploadify
1 appname=$("#appname").val();
2 $("#uploadify").uploadify({
3 'swf' : '<%=basePath%>/Backstage/Style/jQuery-uploadify/uploadify.swf',
4 // 'script' : 'ProductAction!fileUpload.do',//
5 'uploader': 'AppVersionAction!fileUpload.do?appname='+appname ,
6 'cancelImg' : '<%=basePath%>/Backstage/include/easyvalidator/images/vtip_arrow.png',
7 'folder' : '/uplaod/temp',//
8 'queueID' : 'fileQueue',// id
9 'fileObjName':'uploadify',
10 'queueSizeLimit' : 5,
11 'fileDesc' : ' ',
12 'fileTypeExts' : '*.apk;*.ipa;*.png', // , fileDesc
13 'auto' : false,
14 'multi' : true,
15 'simUploadLimit' : 2,
16 'buttonText' : ' ',
17 'onQueueComplete' : function(file,data,response) {
18 picFlag = true;
19 }
20 });
1 <input type="file" name="uploadify" id="uploadify" />
2 <input id="appname" type="text" value="<s:property value="version.appName"/>" name="version.appName" size="30" maxlength="32" data-options="required:true,missingMessage:' '" class="easyui-validatebox" /><font color="red"> *</font>
2. action 및 서비스
1 public void addVersion() {
2 String appname= getRequest().getParameter("appname");
3 UploadImg upload = new UploadImg();
4 try {
5 /** **/
6 version.setId(Constants.getUUID());
7 version.setCreateTime(Constants.getSimpleDateFormat3());
8
9 /** **/
10 List<String> files = (List<String>) getSession().getAttribute("files");
11 String filesext=(String) getSession().getAttribute("fileExt");
12 String updateUrl=(String) getSession().getAttribute("fileName1");
13 if (files != null) {
14 SimpleDateFormat yearFormat = new SimpleDateFormat("yyyyMMdd");
15 String folderName = Constants.versionFileSavePath + "/" + yearFormat.format(new Date()) ;
16 String newFileName=appname+"."+filesext;
17 for (int i = 0; i < files.size(); i++) {
18 upload.moveAndSaveFile(getRequest(), "/Upload/temp" +files.get(i), "/Upload/"+folderName,newFileName);
19 }
20 version.setUpdateUrl(updateUrl);
21 // commodityInfo.setImageDir("/Upload/" + folderName);
22 }
23 getSession().removeAttribute("files");
24 getSession().removeAttribute("fileName1");
25 this.wfAppVersionService.addObject(version);
26 String json = JSON.toJSONString(version);
27 json = json.replace("}", ",\"tips\":\" \"}");
28 getResponse().setContentType("text/html;charset=utf-8");
29 getResponse().getWriter().println(json);
30 } catch (Exception ex) {
31 ex.printStackTrace();
32 try {
33 getResponse().setStatus(555);
34 getResponse().getWriter().println(" ");
35 Logger.getLogger(AppVersionAction.class).info(" ");
36 } catch (IOException e) {
37 e.printStackTrace();
38 }
39 }
40 }
1 public void copyAndUpateFile(HttpServletRequest request,String oldPath, String newPath, String newName) {
2 try {
3 int bytesum = 0;
4 int byteread = 0;
5 System.out.println("@@newPath: "+newPath);
6 File oldfile = new File(request.getRealPath("/")+oldPath);
7 if (oldfile.exists()) { //
8 //
9 if (newPath.split("/").length > 0) {
10 String[] paths = newPath.split("/");
11 String path = request.getRealPath("/") ;
12 for (int i = 0; i < paths.length; i++) {
13 path += paths[i] + "/";
14 File saveDirFile = new File(path);
15 if (!saveDirFile.exists()) {
16 saveDirFile.mkdirs();
17 }
18 }
19 }
20 File file=new File(request.getRealPath("/")+newPath+"/"+"cbt_"+newName);
21 file.createNewFile();
22 InputStream inStream = new FileInputStream(request.getRealPath("/")+oldPath); //
23 FileOutputStream fs = new FileOutputStream(request.getRealPath("/")+newPath+"/"+"cbt_"+newName);
24 byte[] buffer = new byte[1444];
25 while ((byteread = inStream.read(buffer)) != -1) {
26 bytesum += byteread; //
27 fs.write(buffer, 0, byteread);
28 }
29 inStream.close();
30 }
31 } catch (Exception e) {
32 System.out.println(" ");
33 e.printStackTrace();
34
35 }
36 }
37
38 /**
39 * tmp
40 * @Title: UploadImg
41 * @param: @param request
42 * @param: @param oldPath
43 * @param: @param newPath
44 * @param: @param newName
45 * @return:
46 * @throws:
47 * @Description: TODO
48 */
49 public void moveAndSaveFile(HttpServletRequest request,String oldPath, String newPath,String newName) {
50 copyAndUpateFile(request,oldPath, newPath,newName);
51 String fileExt = oldPath.substring(oldPath.lastIndexOf(".") + 1).toLowerCase();
52 System.out.println("oldPath: "+oldPath+"###NewPath: "+newPath+" fileExt: "+fileExt);
53 delFile(request,oldPath);
54
55 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
uploadify 파일 업로드 사용1. jsp 코드 2. action 및 서비스...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.