content: package com.wenmrong.community1.community.controller;
  
  import com.wenmrong.community1.community.dto.FileDTO;
  import com.wenmrong.community1.community.provider.OssClientAuthorization;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.multipart.MultipartFile;
  import org.springframework.web.multipart.MultipartHttpServletRequest;
  
  import javax.servlet.http.HttpServletRequest;
  import java.io.IOException;
  
  @Controller
  public class FileController {
      @Autowired
      private OssClientAuthorization ossClientAuthorization;
      @RequestMapping("/file/upload")
      @ResponseBody
      public FileDTO upload(HttpServletRequest request){
          MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
          MultipartFile file = multipartRequest.getFile("editormd-image-file");
          try {
              String urlFileName = ossClientAuthorization.upload(file.getInputStream(),file.getOriginalFilename());
              FileDTO fileDTO = new FileDTO();
              fileDTO.setSuccess(1);
              fileDTO.setUrl(urlFileName);
              return fileDTO;
          } catch (IOException e) {
              e.printStackTrace();
          }
          FileDTO fileDTO = new FileDTO();
          fileDTO.setSuccess(1);
          fileDTO.setUrl("/images/iceman.png");
          return fileDTO;
      }
  
  }
  