image.png

    1. package com.wzy.oss.controller;
    2. import com.wzy.commonutils.R;
    3. import com.wzy.oss.service.OssService;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.CrossOrigin;
    6. import org.springframework.web.bind.annotation.PostMapping;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import org.springframework.web.bind.annotation.RestController;
    9. import org.springframework.web.multipart.MultipartFile;
    10. @RestController
    11. @RequestMapping(value = "/eduoss/fileoss")
    12. @CrossOrigin//跨域
    13. public class OssController {
    14. @Autowired
    15. private OssService ossService;
    16. /*
    17. * @description 长传头像功能
    18. * @author WangZiyao
    19. * @date 2021/9/20 0020 15:35
    20. * @param [org.springframework.web.multipart.support.MultipartFilter]
    21. * @return com.wzy.commonutils.R
    22. */
    23. @PostMapping(value = "/uploadOssFile")
    24. public R uploadOssFile(MultipartFile file) {
    25. //MultipartFilter:获取上传文件,它是固定的类型。
    26. //上传头像,并返回上传到oss的头像的路径
    27. String url = ossService.uploadFileAvatar(file);
    28. return R.ok().data("url",url);
    29. }
    30. }