Skip to content

unikueltd/file-storage-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Storage Spring Boot Starter

Spring Boot application integrates file-storage, support various storage engines.

Quickstart

  • Import dependencies
    <dependency>
        <groupId>cn.unikue.springstarter</groupId>
        <artifactId>file-storage-spring-boot-starter</artifactId>
        <version>LATEST</version>
    </dependency>

By default, this starter will auto take effect, you can turn it off by spring.file-storage.enabled = false

  • Configure Spring Boot application.yml with prefix spring.file-storage
spring:
    file-storage:
        concat-date: true
        storage-type: 'minio'
        local:
            entry-path: '/path/to/your/storage'
            domain: 'http://localhost:8090'
        minio:
            endpoint: 'localhost'
            port: 9000
            access-key: 'minio'
            secret-key: 'minio123'
            bucket-name: 'demo-bucket'
            access-control: 'public-read'
        aliyun:
            endpoint: 'https://oss-cn-beijing.aliyuncs.com'
            access-key: 'your-access-key'
            secret-key: 'your-secret-key'
            region: 'cn-beijing'
            bucket-name: 'demo-bucket'
            access-control: 'public-read'
        tencent:
            endpoint: 'https://cos.ap-beijing.myqcloud.com'
            secret-id: 'your-secret-id'
            secret-key: 'your-secret-key'
            region: 'ap-beijing'
            bucket-name: 'demo-bucket'
            access-control: 'public-read'
  • Then, in your code, you can use FileStorageComposer to store and retrieve files
@Service
public class DemoService {
    @Autowired
    private FileStorageComposer storageComposer;

    public void demoMethod() {
        // Uploads a file, or a pure text, or a byte array, or an input stream
        storageComposer.uploadObject();

        // Checks if exist an object
        storageComposer.existsObject(objectKey, pathPrefix);

        // Downloads an object as an input stream
        storageComposer.downloadObject(objectKey, pathPrefix);

        // Downloads an object as a file
        storageComposer.downloadObjectTo(objectKey, pathPrefix, targetFile);

        // Removes an object
        storageComposer.removeObject(objectKey, pathPrefix);

        // Gets the object URL
        storageComposer.getObjectUrl(objectKey, pathPrefix);
        storageComposer.getObjectUrl(objectKey, pathPrefix, expiration);
        
        // Gets the raw client for advanced usage
        storageComposer.getRawClient();
        storageComposer.getRawClientAs(expectType);
    }
}

Document

Requirement

  • jdk 17+

License

This project is under the Apache License 2.0

See the NOTICE.txt file for required notices and attributions.

Donation

You like this package? Then donate to us to support the development.

Copyright

Beijing Unikue Network Technology Ltd.

Website

About

File Storage for Spring Boot Starter

Resources

License

Stars

Watchers

Forks

Languages