preface

Based on Minio, Spring Boot is used to build file microservice. The code address

The development environment

  • JDK 1.8
  • SpringBoot 2.5.3
  • MySQL 8
  • Minio

instructions

  • Execute file_server.sql initial database and tables

  • Execute docker-comemage. yml to start the Minio service

  • Start the program, visit http://localhost:9090/swagger-ui/ to view has been implementing an interface

  • configuration

# Main configuration description
# minio
minio:
  Minio service address, account password
  endpoint: http://localhost:9000
  user: minio
  password: minio123
  bucket: ${spring.application.name:default}
  Pre-signed URL validity period (default one day)
  expire: 86400
# Download related
download:
  # Whether to use Minio pre-signed url for external access, no to use host+ API joint address
  presigned: true
  Java service access address
  host: http://localhost:9090
  The API interface for downloading files must be the same as the download URL defined by Controller. If different forwarding processing by proxy
  api: files/download
Copy the code
  • Pre sign the upload

    Directly upload files to the Minio server to avoid transfer and improve upload speed

    • The front firstPOSTrequest/files/presigned, generate a giveHTTP PUTRequest use ofpresigned URL. You can use this on the front endURLTo upload
    • Front end byPUTRequest to sign beforehandurlUpload a file
    • The lastPOSTrequest/files/finisheduploaded
  • @ FillFiles annotations

    With the FillFileSerializer serializer, the file list corresponding to the service ID is automatically filled

    public class FillFilesTestVO implements Serializable {
    
        private String bizId;
    
        @FillFiles("bizId")
        @JsonSerialize(nullsUsing = FillFileSerializer.class)
        private List<UploadedFileVO> files;
    }
    Copy the code

Interface implementation