Springboot存储零时图片

Springboot存储零时图片

目的是为了给图片加上水印 包括文字和图片水印 然后将图片保存至文件服务器 返回前端路径

	`遇到的问题:
        1. 在加完水印之后图片需要输出保存
        2. 从文件服务器获取图片时需要使用的URL
			URL url = new URL(path);
        	Image srcImg = ImageIO.read(url); // 文件转化为图片 	
        3. 保存图片的路径需要获取

`

	// 构造请求头
    `HttpHeaders headers = new HttpHeaders();
    
    MediaType type = MediaType.parseMediaType("multipart/form-data");
    
    headers.setContentType(type);
    // 获取路径
	String path = ResourceUtils.getURL("classpath:").getPath();
    
	FileSystemResource fileSystemResource = new FileSystemResource(path + "测试.png");

    MultiValueMap form = new LinkedMultiValueMap<>();
    
    // 添加参数
    form.add("file", file);
    
    form.add("bucketName", "bucketName");
    
    // 请求
    HttpEntity> files = new HttpEntity<>(form, headers);
    
    // 请求
    ResponseEntity responseResponseEntity = restTemplate.postForEntity(url, files, Map.class);`

你可能感兴趣的:(spring,boot)