• 直接在FormData里携带文件

      public void File(MultipartFile file, String id) throws IOException {
        // 获取输入流/文件名/扩展名~~~~
        InputStream is = file.getInputStream();
        String fileName = file.getOriginalFilename();
        String ext = fileName.substring(fileName.lastIndexOf("."));
      }
  • 文件上传到OSS后返回文件名

    public void File(String fileName, String id) throws IOException {
      //根据文件名获取完整路径
      String fullPath = getPath(fileName);
      if (isResourceExist(fullPath)) {
        throw new ServiceException("文件不存在");
       }
      URL httpUrl = new URL(fullPath);
      URLConnection urlConnection = httpUrl.openConnection();
      InputStream is = urlConnection.getInputStream();
    }

拾柒_
87 声望1 粉丝