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

SpringBoot整合FastDFS方法過(guò)程詳解

 更新時(shí)間:2020年05月07日 10:14:08   作者:秋風(fēng)颯颯吹  
這篇文章主要介紹了SpringBoot整合FastDFS方法過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

一.pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.wj</groupId>
  <artifactId>fastdsf-boot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>fastdsf-boot</name>
  <description>Demo project for Spring Boot</description>
 
  <properties>
    <java.version>1.8</java.version>
  </properties>
 
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
 
 
 
    <dependency>
      <groupId>com.github.tobato</groupId>
      <artifactId>fastdfs-client</artifactId>
      <version>1.26.2</version>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.junit.vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
 
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
 
</project>

二.application.yml

#fastdfs 配置
fdfs:
so-timeout: 150000
connect-timeout: 150000 #超時(shí)時(shí)間
thumb-image:
width: 150
height: 150
tracker-list:
- 111.111.111.111:22122 #ip:端口號(hào)
spring:
thymeleaf:
prefix: classpath:/templates/
servlet:
multipart:
max-file-size: 50MB #單次單個(gè)文件最大大小
max-request-size: 50MB #單次上傳所有文件的總大小<br>  #注意,這里springboot默認(rèn)配置的大小是1MB和10MB,可能不夠用,具體參考MultipartProperties.java

三.FastUtil.java 前提先將Nginx和FastDFS整合

@Component
public class FastUtil {
 
  private final Logger logger = LoggerFactory.getLogger(FastUtil.class);
 
  @Autowired
  private FastFileStorageClient fastFileStorageClient;
 
  /**
   * 文件上傳
   * 最后返回fastDFS中的文件名稱;
   *
   * @param bytes   文件字節(jié)
   * @param fileSize 文件大小
   * @param extension 文件擴(kuò)展名
   * @return fastDfs路徑
   */
  public String uploadFile(byte[] bytes, long fileSize, String extension) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    StorePath storePath = fastFileStorageClient.uploadFile(byteArrayInputStream, fileSize, extension, null);
    return "http://111.111.111.111/"+storePath.getFullPath();
  }
 
  public byte[] downloadFile(String group,String path) throws IOException {
    DownloadByteArray downloadByteArray = new DownloadByteArray();
    byte[] bytes = fastFileStorageClient.downloadFile(group, path, downloadByteArray);
    return bytes;
  }
 
}

四.配置類 FdfsConfig.java

@Configuration
@Import(FdfsClientConfig.class)
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class FdfsConfig {
}

五.Controller

@RestController
public class FdfsController {
 
  @Autowired
  private FastUtil fastDFSClientWrapper;
 
  private final Logger logger = LoggerFactory.getLogger(FdfsController.class);
 
  @PostMapping("/upload")
  @ResponseBody
  public String upload(MultipartFile file) throws Exception {
    byte[] bytes = new byte[0];
    try {
      bytes = file.getBytes();
    } catch (IOException e) {
      logger.error("獲取文件錯(cuò)誤");
      e.printStackTrace();
    }
    //獲取源文件名稱
    String originalFileName = file.getOriginalFilename();
    //獲取文件后綴--.doc
    String extension = originalFileName.substring(originalFileName.lastIndexOf(".") + 1);
    String fileName = file.getName();
    //獲取文件大小
    long fileSize = file.getSize();
    System.out.println(originalFileName + "==" + fileName + "==" + fileSize + "==" + extension + "==" + bytes.length);
    String string = fastDFSClientWrapper.uploadFile(bytes, fileSize, extension);
    return string;
  }
}

六.前端頁(yè)面 index.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
   xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
  <meta charset="UTF-8" />
  <title>Insert title here</title>
</head>
<body>
<h1 th:inlines="text">文件上傳</h1>
<form action="upload" method="post" enctype="multipart/form-data">
  <p>選擇文件: <input type="file" name="file"/></p>
  <p><input type="submit" value="提交"/></p>
</form>
</body>
</html>

七.開(kāi)始上傳

最后在頁(yè)面上返回一個(gè)URL,可以直接訪問(wèn)

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

相關(guān)文章

  • Java程序單實(shí)例運(yùn)行的簡(jiǎn)單實(shí)現(xiàn)

    Java程序單實(shí)例運(yùn)行的簡(jiǎn)單實(shí)現(xiàn)

    這篇文章主要介紹了Java程序單實(shí)例運(yùn)行的簡(jiǎn)單實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java使用File類遍歷目錄及文件實(shí)例代碼

    Java使用File類遍歷目錄及文件實(shí)例代碼

    本篇文章主要介紹了Java使用File類遍歷目錄及文件實(shí)例代碼,詳細(xì)的介紹了File類的使用,有興趣的可以了解一下。
    2017-04-04
  • 常用輸入字節(jié)流InputStream介紹

    常用輸入字節(jié)流InputStream介紹

    下面小編就為大家?guī)?lái)一篇常用輸入字節(jié)流InputStream介紹。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • Java編程實(shí)現(xiàn)軌跡壓縮之Douglas-Peucker算法詳細(xì)代碼

    Java編程實(shí)現(xiàn)軌跡壓縮之Douglas-Peucker算法詳細(xì)代碼

    這篇文章主要介紹了Java編程實(shí)現(xiàn)軌跡壓縮之Douglas-Peucker算法詳細(xì)代碼,具有一定借鑒價(jià)值,需要的朋友可以參考。
    2017-11-11
  • java實(shí)現(xiàn)2048小游戲

    java實(shí)現(xiàn)2048小游戲

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)2048小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-02-02
  • Java女裝商城系統(tǒng)的實(shí)現(xiàn)流程

    Java女裝商城系統(tǒng)的實(shí)現(xiàn)流程

    讀萬(wàn)卷書(shū)不如行萬(wàn)里路,只學(xué)書(shū)上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+SSM+jsp+mysql+maven實(shí)現(xiàn)一個(gè)女裝商城系統(tǒng),大家可以在過(guò)程中查缺補(bǔ)漏,提升水平
    2021-11-11
  • 怎么在AVD上安裝apk軟件

    怎么在AVD上安裝apk軟件

    執(zhí)行 Windows 開(kāi)始菜單 => 所有程序 => 附件 => 命令提示符 或通過(guò) Win+R 組合鍵調(diào)出 運(yùn)行 對(duì)話框輸入cmd 單擊確定即可
    2013-09-09
  • SVN導(dǎo)入maven項(xiàng)目報(bào)錯(cuò)解決方案

    SVN導(dǎo)入maven項(xiàng)目報(bào)錯(cuò)解決方案

    這篇文章主要介紹了SVN導(dǎo)入maven項(xiàng)目報(bào)錯(cuò)解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-12-12
  • springboot整合日志處理Logback的實(shí)現(xiàn)示例

    springboot整合日志處理Logback的實(shí)現(xiàn)示例

    Logback是由log4j創(chuàng)始人設(shè)計(jì)的又一個(gè)開(kāi)源日志組件,本文主要介紹了springboot整合日志處理Logback,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-01-01
  • 解決SpringBoot web項(xiàng)目啟動(dòng)后立即關(guān)閉的問(wèn)題

    解決SpringBoot web項(xiàng)目啟動(dòng)后立即關(guān)閉的問(wèn)題

    這篇文章主要介紹了解決SpringBoot web項(xiàng)目啟動(dòng)后立即關(guān)閉的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08

最新評(píng)論

巴东县| 临清市| 南溪县| 佛教| 永州市| 新巴尔虎左旗| 大厂| 鄄城县| 宾阳县| 洱源县| 长春市| 东港市| 仪征市| 泰安市| 县级市| 东乌珠穆沁旗| 延吉市| 昌平区| 梁河县| 曲阜市| 平南县| 仁寿县| 开江县| 漳州市| 松滋市| 武城县| 潞城市| 石景山区| 荣昌县| 河池市| 台北市| 普兰县| 阿勒泰市| 华宁县| 商河县| 乐陵市| 清镇市| 临邑县| 浪卡子县| 虞城县| 长治县|