• 记录-Jquery uploadify文件上传实例


    原本做的是from表单的文件上传,后来因需要用ajax异步,so接触到了Jquery uploadify上传

    贴上代码,以供参考

    需要引入的js文件

        <link href="../res/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
        <script src="../res/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>

    下面是HTML代码

     <input type="file" id="file" name="file"  /> 

    下面是Jquery代码

    下面蓝色部分没用

    $("#file").uploadify({ height: 14, swf: '/res/uploadify/uploadify.swf', uploader: '../member/getAllByExcel', 100, fileTypeExts: '*.xls', errorMsg: "不支持文件格式", buttonText:"Excel上传", multi :false, onUploadSuccess: function (file,data ,state) { var jsonData =$.parseJSON(data.replace(/\/g,"\\")); if(data.msg){ alert(unescape(data.msg)); return; } $.appendMainPic(jsonData.images[0].url,jsonData.images[0].id); var orgValue = $("#Card_Pic_mainPic").val()+""; orgValue+=","+jsonData.images[0].id; $("#Card_Pic_mainPic").val(orgValue); }, onQueueComplete :function(a,b,c){} });

    下面是后台代码

    @RequestMapping(value="getAllByExcel" ,method = RequestMethod.POST)
        public Object getAllByExcel(HttpServletRequest request,HttpServletResponse response, ModelMap model){
            Map<String, Object> resMap=new HashMap<String, Object>();
            MultipartHttpServletRequest mulltipartRequest=(MultipartHttpServletRequest)request;
            
            Map<String, MultipartFile> fileMap = mulltipartRequest.getFileMap();
            for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
                MultipartFile files = entity.getValue();
                //MultipartFile mf = entity.getValue();
                String path=request.getSession().getServletContext().getRealPath("/WEB-INF/res/upload");
                String fileName=files.getOriginalFilename();
                
                try {
                    
                  InputStream inputStream=files.getInputStream();
                    
                    byte[] b = new byte[1048576];
                    int length = inputStream.read(b);
                    path += "\" + fileName;
                    // 文件流写到服务器端
                    FileOutputStream outputStream = new FileOutputStream(path);
                    outputStream.write(b, 0, length);
                    inputStream.close();
                    outputStream.close();
                  
                    
                    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            
            //MultipartFile files=mulltipartRequest.getFile(null);
            //得到上传服务器路径
            resMap.put("msg", "录入成功");
            return resMap;
        }
  • 相关阅读:
    VUE vue和element框架搭配实现导航跳转,底部导航跳转页面
    【HDFS篇14】HA高可用 --- Federation架构设
    【HDFS篇13】HA高可用 --- YARN-HA集群配置
    【HDFS篇12】HA高可用 --- HDFS-HA集群配置
    【HDFS篇11】HA高可用
    【HDFS篇10】DataNode相关概念
    【HDFS篇09】集群安全模式
    【HDFS篇08】NameNode故障处理
    【HDFS篇07】NameNode和SecondearyNameNode
    【HDFS篇06】HDFS数据读写流程
  • 原文地址:https://www.cnblogs.com/dscs/p/5259239.html
Copyright © 2020-2023  润新知