• fastdfs


    /**
         * 图片上传
         * @return
         */
        @PostMapping(value = {"/uploadPicture","/uploadHead"})
        public Result uploadHeadPortrait(HttpSession session,@RequestParam("file") MultipartFile file,HttpServletRequest request){
            User user = (User)session.getAttribute("user");
            if(null == user){
                return Result.error("no user");
            }
            if (file.getOriginalFilename().isEmpty()){
                return Result.error("file name error");
            }
            try {
                FastDFSClient fastDFSClient = new FastDFSClient("classpath:conf/fdfs.conf");
                //获取文件名
                String originalFilename = file.getOriginalFilename();
                //获取文件后缀名
                String extName = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
                //拼接图片服务器路径
                String filename = IMAGE_SERVER_URL + fastDFSClient.uploadFile(file.getBytes(), extName);
    
    
                //获取请求路径
                String url = request.getRequestURI().trim();
                if(url.equals("/uploadPicture")){
                    //保存相册
                    Picture picture = new Picture();
                    picture.setUser(user);
                    picture.setCreateTime(new Date());
                    picture.setPath(filename);
                    pictureService.save(picture);
                    return Result.success();
                }else if(url.equals("/uploadHead")){
                    //保存用户头像
                    user.setHeadPortrait(filename);
                    userService.upload(user);
                    return Result.success();
                }
                return Result.error("url error");
            }catch (Exception e){
                e.printStackTrace();
                return Result.error("picture upload failed");
            }
        }
    
  • 相关阅读:
    防火墙2
    SVN:多版本库环境的搭建
    安装SVN服务端
    springContext
    linux centos7安装 mysql-5.7.11
    ajax struts2 前后台 交互
    Spring的 classpath 通配符加载配置文件
    使用甘特图实现服务计划的可视化
    条形码软件开发包Dynamic .NET TWAIN v5.0提供WPF功能
    快来玩“Gift大转盘”百分百赚好礼
  • 原文地址:https://www.cnblogs.com/xiongyungang/p/10797447.html
Copyright © 2020-2023  润新知