zoukankan      html  css  js  c++  java
  • 图片上传代码

    
    
    public static String imageUpdate(MultipartFile multfile, HttpServletRequest request,String pathName){
            if (!multfile.isEmpty()) {
                CommonsMultipartFile commonsmultipartfile = (CommonsMultipartFile) multfile;
                DiskFileItem diskFileItem = (DiskFileItem) commonsmultipartfile.getFileItem();
                File file = diskFileItem.getStoreLocation();
                String fileName = System.nanoTime() + multfile.getOriginalFilename();
    
                String path = Global.getUserfilesBaseDir() + "/userfiles/"+pathName+"/";
                try{
                    File newFile = new File(path);
                    if (!newFile.exists()) {
                        newFile.mkdirs();
                    }
    
                    newFile=new File(path+fileName);
                    newFile.createNewFile();
                    OutputStream os = null;
                    byte[] bs = new byte[1024];
                    int len;
                    if (!file.exists()) {
                        file.mkdirs();
                    }
                    InputStream in = null;
                    try {
                        in = new FileInputStream(file);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    os = new FileOutputStream(newFile);
                    while ((len = in.read(bs)) != -1) {
                        os.write(bs, 0, len);
                    }
                    file.delete();
                    os.close();
                    in.close();
                }catch (Exception e){
                    e.printStackTrace();
                    return "";
                }
                String url = "http://" + request.getServerName() //服务器地址
                        + ":"
                        + request.getServerPort()           //端口号
                        + "/userfiles/" + pathName + "/";//项目名称
                return url+fileName;
            }
            return "";
        }
    
    
  • 相关阅读:
    输入框input只能输入数字和小数点
    ES6判断数组是否存在重复元素
    AutoPostBack的含义
    首次的boe with wss
    我的msn能在w2k3上使用了哈哈
    挑战excel
    wss的webpart的3种开发方式
    我来操作dts olap
    My dbconn of ASP
    sharepoint学习理解过程
  • 原文地址:https://www.cnblogs.com/-strong/p/9718296.html
Copyright © 2011-2022 走看看