Skip to content

jwenjian/spring-boot-starter-fastdfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-boot-starter-fastdfs

A spring boot starter for fastdfs java client.

Why

Normally, we use the fastdfs java client in the fastdfs_client.conf way. It works well, util we start to using spring boot.

The configuration file way cannot meet out active profile of spring boot, like: dev, test, pro, we want the client more smart in a spring boot way.

So, here it comes.

How to install

  1. Add a maven repository to your pom.xml
	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>
  1. Add the dependency
	<dependency>
	    <groupId>com.github.jwenjian</groupId>
	    <artifactId>spring-boot-starter-fastdfs</artifactId>
	    <version>${version}</version>
	</dependency>

How to config

If you know how to config original client_conf.properties, then you will know how to config this project.

Add configuration items to your application-${profile}.properties or application-${profile}.yml:

  • Properties
spring.fastdfs.tracker_servers= # the tracker server urls
spring.fastdfs.connect_timeout_in_seconds= # the connect timeout in seconds
spring.fastdfs.network_timeout_in_seconds= # the network timeout in seconds
spring.fastdfs.charset= # the.charset
spring.fastdfs.http_anti_steal_token= # the http anti-steal token
spring.fastdfs.http_secret_key= # the http secret key
spring.fastdfs.http_tracker_http_port= # the http tracker http port
spring.fastdfs.init_conn_on_load= # if init connection on server loaded
  • Yaml
spring:
    fastdfs:
        tracker_servers: # the tracker server urls
        connect_timeout_in_seconds: # the connect timeout in seconds
        network_timeout_in_seconds: # the network timeout in seconds
        charset: # the.charset
        http_anti_steal_token: # the http anti-steal token
        http_secret_key: # the http secret key
        http_tracker_http_port: # the http tracker http port
        init_conn_on_load: # if init connection on server loaded

How to use

Below is the sample code:

@RestController
public class DemoController {

    @Autowired
    private FastDfsManager fastDfsManager;


    @PostMapping("/upload")
    public void upload(final MultipartFile file) throws IOException, MyException {
        final String[] results = fastDfsManager.getStorageClient1().upload_file(file.getBytes(), "jpg", null);

        System.out.println(Arrays.toString(results));
    }

}