1. #1
    Ext User
    Join Date
    Dec 2008
    Posts
    6
    Vote Rating
    0
    yourgame2 is on a distinguished road

      0  

    Talking SWFUpload with Extjs3.0 Component

    屏幕快照 2009-12-16 上午12.15.48.jpg

    Css and resources file size too big!

    Code:
    Ext.onReady(function() {
        var win = new Ext.Window({
            title : '多文件上传示例',
            width : 500,
            height : 500,
            resizable : false,
            layout : 'fit',
            items : [{
                xtype : 'uploadpanel',
                uploadUrl : 'uploadFiles.action',
                filePostName : 'myUpload', // 这里很重要,默认值为'fileData',这里匹配action中的setMyUpload属性
                flashUrl : 'js/swfupload.swf',
                fileSize : '500 MB',
                height : 400,
                border : false,
                fileTypes : '*.*', // 在这里限制文件类型:'*.jpg,*.png,*.gif'
                fileTypesDescription : '所有文件',
                postParams : {
                    path : 'files\\' // 上传到服务器的files目录下面
                }
            }],
            bbar : ['作者:廖瀚卿 | QQ:3990995 | 博客:http://yourgame.javaeye.com']
        });
    
        win.show();
    });
    Code:
    package com.lhq.uploader;
    
    import java.io.File;
    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;
    import java.util.HashMap;
    import java.util.Map;
    
    /**
     * FileAction.java Create on 2008-12-18 上午09:16:22
     * 
     * 说明:文件处理
     * 
     * Copyright (c) 2008 by yourgame.
     * 
     * @author 廖瀚卿
     * @version 1.0
     */
    @SuppressWarnings("serial")
    public class FileAction extends BaseAction {
        private Map<String, Object> infos = new HashMap<String, Object>();
    
        public static final String ROOT = "upload\\";
    
        private File myUpload;
    
        private String myUploadContentType;
    
        private String myUploadFileName;
    
        private String path;
    
        private boolean success;
    
        /**
         * 上传文件
         * 
         * @return
         */
        public String uploadFiles() {
            String rootPath = getSession().getServletContext().getRealPath("/");
            rootPath += ROOT;
            String sp = rootPath + getPath();
            MyUtils.mkDirectory(sp);
            try {
                MyUtils.upload(getMyUploadFileName(), sp, getMyUpload());
                this.success = true;
            } catch (RuntimeException e) {
                e.printStackTrace();
            }
            return SUCCESS;
        }
    
        public File getMyUpload() {
            return myUpload;
        }
    
        public void setMyUpload(File myUpload) {
            this.myUpload = myUpload;
        }
    
        public String getMyUploadContentType() {
            return myUploadContentType;
        }
    
        public void setMyUploadContentType(String myUploadContentType) {
            this.myUploadContentType = myUploadContentType;
        }
    
        public String getMyUploadFileName() {
            return myUploadFileName;
        }
    
        public void setMyUploadFileName(String myUploadFileName) {
            this.myUploadFileName = myUploadFileName;
        }
    
        public boolean isSuccess() {
            return success;
        }
    
        public void setSuccess(boolean success) {
            this.success = success;
        }
    
        public String getPath() {
            return path;
        }
    
        public void setPath(String path) throws UnsupportedEncodingException {
            this.path = URLDecoder.decode(path, "UTF-8");
        }
    
        public Map<String, Object> getInfos() {
            return infos;
        }
    
        public void setInfos(Map<String, Object> infos) {
            this.infos = infos;
        }
    }
    Code:
    package com.lhq.uploader;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class MyUtils {
    
        /**
         * 上传文件
         * 
         * @param savePath
         *            文件的保存路径
         * @param uploadFile
         *            被上传的文件
         * @return newFileName
         */
        public static String upload(String uploadFileName, String savePath, File uploadFile) {
            String newFileName = getUUIDName(uploadFileName, savePath);
            try {
                FileOutputStream fos = new FileOutputStream(savePath + newFileName);
                FileInputStream fis = new FileInputStream(uploadFile);
                byte[] buffer = new byte[1024];
                int len = 0;
                while ((len = fis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return newFileName;
        }
    
        public static String getUUIDName(String fileName, String dir) {
            String[] split = fileName.split("\\.");
            String extendFile = "." + split[split.length - 1].toLowerCase();
            return java.util.UUID.randomUUID().toString() + extendFile;
        }
    
        /**
         * 根据路径创建一系列的目录
         * 
         * @param path
         */
        public static boolean mkDirectory(String path) {
            File file = null;
            try {
                file = new File(path);
                if (!file.exists()) {
                    return file.mkdirs();
                }
            } catch (RuntimeException e) {
                e.printStackTrace();
            } finally {
                file = null;
            }
            return false;
        }
    
    }

  2. #2
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default

    this looks like a Gxt example.
    shall i move this to the Gxt Examples forum instead?

  3. #3
    Ext User
    Join Date
    Dec 2008
    Posts
    6
    Vote Rating
    0
    yourgame2 is on a distinguished road

      0  

    Default

    Quote Originally Posted by mystix View Post
    this looks like a Gxt example.
    shall i move this to the Gxt Examples forum instead?
    No Gxt, is ExtJS 3.0 example

  4. #4
    Sencha User
    Join Date
    Jan 2009
    Posts
    34
    Vote Rating
    0
    jerrel is on a distinguished road

      0  

    Default xtype : 'uploadpanel' ?? not an object

    Dear yourgame2

    I tried out your ext 3.0 example, but i noticed that ext cannot find xtype : 'uploadpanel'.
    Where can dowload the script which defines this filetype.

    regards
    J

  5. #5
    Sencha User Achilles's Avatar
    Join Date
    Oct 2008
    Location
    guangzhou, china
    Posts
    12
    Vote Rating
    0
    Achilles is on a distinguished road

      0  

    Default

    good job!~

  6. #6
    Sencha User
    Join Date
    Mar 2012
    Posts
    1
    Vote Rating
    0
    wanzyly123 is on a distinguished road

      0  

    Default

    Excuse me,where to download the uploadpanel JS file.

  7. #7
    Sencha - Tools Team arthurakay's Avatar
    Join Date
    Sep 2008
    Location
    Antioch, IL
    Posts
    1,416
    Vote Rating
    55
    arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice arthurakay is just really nice

      0