最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Java寫minio客戶端實(shí)現(xiàn)上傳下載文件

 更新時間:2020年05月18日 11:19:16   作者:帥過驢的袋鼠  
這篇文章主要介紹了基于Java寫minio客戶端實(shí)現(xiàn)上傳下載文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

前言:

  確保已經(jīng)安裝了minio的服務(wù)端

代碼:

pom.xml

<dependency>
  <groupId>io.minio</groupId>
  <artifactId>minio</artifactId>
  <version>7.0.2</version>
</dependency>

application.yml

server:
 port:90
minio:
 url: http://10.69.94.140:9000
 accessKey: 賬號
 secretKey: 密碼
 defaultFolder: /

MinioProperties.java

@ConfigurationProperties("minio")
@Data
public class MinioProperties {
  private String url;
  private String accessKey;
  private String secretKey;
  private String defaultFolder;
}

SpringConfig.java

@Configuration
@EnableConfigurationProperties(MinioProperties.class)
@Slf4j
public class SpringConfig {
  @Autowired
  private MinioProperties minioProperties;

  @Bean
  public MinioClient minioClient() {
    try {
      return new MinioClient(minioProperties.getUrl(), minioProperties.getAccessKey(), minioProperties.getSecretKey());
    } catch (Exception e) {
      log.error(e.toString());
    }
    return null;
  }

}

ImagesController.java

@RestController
@RequestMapping("/image")
@Slf4j
@CrossOrigin(origins = "*")
public class ImageController {

  @Autowired
  private FileService fileService;

  /*******
   * Get image file, this method return an image type file which can be displayed in browser.
   * @param bucketName, system, each system should belong a special bucket.
   * @param category, a system may contain multiple category
   * @param fileName
   */
  @GetMapping(value = "/get/{bucketName}/{category}/{objectName}/{fileName}", produces = MediaType.IMAGE_JPEG_VALUE)
  public byte[] get(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
           @PathVariable("objectName") String objectName,
           @PathVariable("fileName") String fileName) throws Exception {
    return fileService.getFile(bucketName, category, objectName);
  }

  @GetMapping("/download/{bucketName}/{category}/{objectName}/{fileName}")
  public void download(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
             @PathVariable("objectName") String objectName,
             @PathVariable("fileName") String fileName, HttpServletResponse response) throws Exception {
    byte[] buffer = fileService.getFile(bucketName, category, objectName);
    response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
    response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
    response.getOutputStream().write(buffer);
    response.flushBuffer();
    response.getOutputStream().close();
  }

  @PostMapping("/upload/{bucketName}/{category}")
  public String upload(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
             @RequestParam("file") MultipartFile file) throws Exception {
    String objectName = UUID.randomUUID().toString();
    fileService.storeFile(bucketName, category, objectName, file.getBytes());
    return String.format("image/get/%s/%s/%s/%s", bucketName, category, objectName, file.getOriginalFilename());
  }
}

FilesController.java

@RestController
@RequestMapping("/files")
@Slf4j
@CrossOrigin(origins = "*")
public class FilesController {

  @Autowired
  private FileService fileService;

  @GetMapping("/download/{bucketName}/{category}/{objectName}/{fileName}")
  public void download(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
             @PathVariable("objectName") String objectName, @PathVariable("fileName") String fileName, HttpServletResponse response) throws Exception {
    byte[] buffer = fileService.getFile(bucketName, category, objectName);
    response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
    response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
    response.getOutputStream().write(buffer);
    response.flushBuffer();
    response.getOutputStream().close();
  }

  @PostMapping("/upload/{bucketName}/{category}")
  public String upload(@PathVariable("bucketName") String bucketName, @PathVariable("category") String category,
             @RequestParam("file") MultipartFile file) throws Exception {
    String objectName = UUID.randomUUID().toString();
    fileService.storeFile(bucketName, category, objectName, file.getBytes());
    return String.format("files/download/%s/%s/%s/%s", bucketName, category, objectName, file.getOriginalFilename());
  }
}

upload.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Upload file test</title>
</head>
<body>
  <form action="http://localhost:90/image/upload/zeng/test" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" value="Submit">
  </form>
</body>
</html>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java實(shí)現(xiàn)Html轉(zhuǎn)Pdf的方法

    Java實(shí)現(xiàn)Html轉(zhuǎn)Pdf的方法

    這篇文章主要介紹了Java實(shí)現(xiàn)Html轉(zhuǎn)Pdf的方法,實(shí)例分析了java基于ITextRenderer類操作頁面及系統(tǒng)自帶字體生成pdf文件的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07
  • SpringCloud可視化鏈路追蹤系統(tǒng)Zipkin部署過程

    SpringCloud可視化鏈路追蹤系統(tǒng)Zipkin部署過程

    這篇文章主要介紹了SpringCloud可視化鏈路追蹤系統(tǒng)Zipkin部署過程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-03-03
  • 詳解Java數(shù)組的排序算法與二分查找法

    詳解Java數(shù)組的排序算法與二分查找法

    這篇文章詳細(xì)給大家介紹了Java數(shù)組的排序算法與二分查找法,文中有詳細(xì)的代碼示例,對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2023-05-05
  • Springboot整合knife4j與shiro的操作

    Springboot整合knife4j與shiro的操作

    這篇文章主要介紹了Springboot整合knife4j與shiro的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Spring Boot非Web項(xiàng)目運(yùn)行的方法

    Spring Boot非Web項(xiàng)目運(yùn)行的方法

    這篇文章主要給大家介紹了關(guān)于Spring Boot非Web項(xiàng)目運(yùn)行的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Java旋轉(zhuǎn)數(shù)組中最小數(shù)字具體實(shí)現(xiàn)(圖文詳解版)

    Java旋轉(zhuǎn)數(shù)組中最小數(shù)字具體實(shí)現(xiàn)(圖文詳解版)

    這篇文章主要給大家介紹了關(guān)于Java旋轉(zhuǎn)數(shù)組中最小數(shù)字具體實(shí)現(xiàn)的相關(guān)資料,旋轉(zhuǎn)數(shù)組,說明數(shù)據(jù)不變,只是改變位置,文中通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-08-08
  • 詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

    詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

    這篇文章主要介紹了詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • struts2自定義MVC框架

    struts2自定義MVC框架

    這篇文章主要為大家詳細(xì)介紹了struts2如何自定義MVC框架,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • 關(guān)于maven下載慢的問題

    關(guān)于maven下載慢的問題

    這篇文章主要介紹了關(guān)于maven下載慢的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • 解析Java虛擬機(jī)中類的初始化及加載器的父委托機(jī)制

    解析Java虛擬機(jī)中類的初始化及加載器的父委托機(jī)制

    這篇文章主要介紹了Java虛擬機(jī)中類的初始化及加載器的父委托機(jī)制,包括命名空間等深層次的知識點(diǎn)講解,需要的朋友可以參考下
    2015-11-11

最新評論

沙田区| 威海市| 都昌县| 崇州市| 林口县| 正宁县| 宜城市| 旺苍县| 泗洪县| 南通市| 武川县| 呼和浩特市| 临潭县| 牙克石市| 扬州市| 商城县| 肃宁县| 方城县| 威信县| 平江县| 绥中县| 河池市| 揭西县| 汽车| 兖州市| 吴堡县| 大名县| 连江县| 论坛| 博客| 章丘市| 大兴区| 刚察县| 方城县| 马关县| 绵阳市| 甘孜县| 阿瓦提县| 巴彦县| 界首市| 阿拉善右旗|