oss上传,阿里云上传oss,带缩略图

 

https://mp.weixin.qq.com/s/obL9JmzDYdkREEJIj_hVIQ

借用工具类

 <dependency>
            <groupId>cn.xuyanwu</groupId>
            <artifactId>spring-file-storage</artifactId>
            <version>0.5.0</version>
        </dependency>

        <!-- 阿里云oss -->
        <dependency>
            <groupId>com.aliyun.oss</groupId>
            <artifactId>aliyun-sdk-oss</artifactId>
            <version>3.10.2</version>
        </dependency>

 

主类

@RestController
public class testController {

    @Autowired
    private FileStorageService fileStorageService;

    /**
     * 
     * 上传文件
     */
    @PostMapping(value = {"/upload"})
    public Object upload(MultipartFile file) {
        FileInfo upload  = fileStorageService.of(file).image(img -> img.size(1000,1000))  //将图片大小调整到 1000*1000
                .thumbnail(th -> th.size(200,200))  //再生成一张 200*200 的缩略图
        .upload();
        return upload;
    }

}

 

主配置文件

spring:
  #文件存储配置(本地、oss)
  file-storage:
    default-platform: aliyun-oss
    thumbnail-suffix: ".min.jpg" #缩略图后缀

    aliyun-oss:
      - platform: aliyun-oss
        enable-storage: true
        access-key: LTAI5t72QXnxxxxxx3dG
        secret-key: 2MwSVL9dStxxxxxxx5GgocWQ
        end-point: oss-cn-qingdao.aliyuncs.com
        bucket-name: taote
        domain: http://oss-cn-qingdao.aliyuncs.com
        base-path: #云平台文件路径
  servlet:
    multipart:
      max-file-size: 10MB
      max-request-size: 50MB

  

ram账号,授权oss的权限。

 

 

启动文件

@EnableFileStorage
@SpringBootApplication
public class Demo5Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo5Application.class, args);
    }

}

 

 

 

posted @ 2022-11-11 22:45  琴声清幽  阅读(1236)  评论(0编辑  收藏  举报