zoukankan      html  css  js  c++  java
  • 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");
            }
        }
    
  • 相关阅读:
    Redis主从复制及主从复制的注意事项
    Redis哨兵(Sentinel)
    Redis慢查询日志(slowlog)
    Memcached缓存雪崩现象
    PHP添加Memcached扩展
    Redis节省空间
    Memcached遇到的问题及解决办法
    C++ explicit关键字学习
    力扣:排序之topK||Kth元素的问题
    软聚类
  • 原文地址:https://www.cnblogs.com/xiongyungang/p/10797447.html
Copyright © 2011-2022 走看看