Spring boot 集成Minio实现文件单文件上传

参考链接:
本地安装使用:
https://blog.csdn.net/qq_34821276/article/details/106176405?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param

docker安装使用:
https://blog.csdn.net/tc979907461/article/details/106673570/

实例代码:
https://github.com/lkzgit/springboot-minio

单纯保存:

@Controller
public class FileController {

	 
	
	@RequestMapping(value = "/api/v1/gopage")  
	public Object index() {
		
		return "index";
	}

	
	
	
    	private static final String filePath = "/Users/jack/Desktop/person/springboot/xdclass_springboot/src/main/resources/static/images/";
   
	
	 	@RequestMapping(value = "upload")
	    @ResponseBody
	    public JsonData upload(@RequestParam("head_img") MultipartFile file,HttpServletRequest request) {
	      
	 		//file.isEmpty(); 判断图片是否为空
	 		//file.getSize(); 图片大小进行判断
	 		
	 		String name = request.getParameter("name");
	 		System.out.println("用户名:"+name);
	        
	 		// 获取文件名
	        String fileName = file.getOriginalFilename();	        
	        System.out.println("上传的文件名为:" + fileName);
	        
	        // 获取文件的后缀名,比如图片的jpeg,png
	        String suffixName = fileName.substring(fileName.lastIndexOf("."));
	        System.out.println("上传的后缀名为:" + suffixName);
	        
	        // 文件上传后的路径
	        fileName = UUID.randomUUID() + suffixName;
	        System.out.println("转换后的名称:"+fileName);
	        
	        File dest = new File(filePath + fileName);
	       
	        try {
	            file.transferTo(dest);
	            
	            return new JsonData(0, fileName);
	        } catch (IllegalStateException e) {
	            e.printStackTrace();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return  new JsonData(-1, "fail to save ", null);
	    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值