mirror of
https://github.com/valitydev/file-storage.git
synced 2024-11-06 00:35:22 +00:00
BJ-314: add swagger config, replace s3client on transferManager
fix pom
This commit is contained in:
parent
8ec3006de5
commit
18aebc6460
64
pom.xml
64
pom.xml
@ -23,9 +23,11 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
|
||||
<shared.resources.version>0.2.1</shared.resources.version>
|
||||
<woody.thrift.version>1.1.15</woody.thrift.version>
|
||||
<file.storage.proto.version>1.8-c23437f</file.storage.proto.version>
|
||||
<geck.version>0.6.8</geck.version>
|
||||
<swagger.version>2.8.0</swagger.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -74,6 +76,16 @@
|
||||
<version>1.18.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test libs -->
|
||||
<dependency>
|
||||
@ -90,11 +102,63 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
|
||||
<targetPath>${project.build.directory}</targetPath>
|
||||
<includes>
|
||||
<include>Dockerfile</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>Dockerfile</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-remote-resources-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-filtering</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<resourceBundles>
|
||||
<resourceBundle>com.rbkmoney:shared-resources:${shared.resources.version}</resourceBundle>
|
||||
</resourceBundles>
|
||||
<attachToMain>false</attachToMain>
|
||||
<attachToTest>false</attachToTest>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>process</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.rbkmoney.file.storage.configuration;
|
||||
|
||||
import com.rbkmoney.file.storage.contorller.UploadFileController;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket api() {
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage(UploadFileController.class.getPackage().getName()))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
docket.forCodeGeneration(true);
|
||||
return docket;
|
||||
}
|
||||
}
|
@ -2,11 +2,16 @@ package com.rbkmoney.file.storage.contorller;
|
||||
|
||||
import com.rbkmoney.file.storage.service.StorageService;
|
||||
import com.rbkmoney.file.storage.service.exception.StorageFileNotFoundException;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -15,13 +20,21 @@ import static com.rbkmoney.file.storage.util.CheckerUtil.checkFile;
|
||||
import static com.rbkmoney.file.storage.util.CheckerUtil.checkString;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1")
|
||||
@Api(description = "File upload API")
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class UploadFileController {
|
||||
|
||||
private final StorageService storageService;
|
||||
|
||||
@PostMapping("/file_storage/upload")
|
||||
@ApiOperation(value = "Request upload file")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "File was uploaded"),
|
||||
@ApiResponse(code = 401, message = "File id not found"),
|
||||
@ApiResponse(code = 500, message = "Internal service error")
|
||||
})
|
||||
@PostMapping("/upload")
|
||||
public ResponseEntity handleFileUpload(@RequestParam(value = "file_id") String fileId,
|
||||
@RequestParam(value = "file") MultipartFile file) {
|
||||
try {
|
||||
@ -37,7 +50,7 @@ public class UploadFileController {
|
||||
return ResponseEntity.notFound().build();
|
||||
} catch (Exception e) {
|
||||
log.error("Error when handleFileUpload e: ", e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to request upload file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.amazonaws.HttpMethod;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.model.*;
|
||||
import com.amazonaws.services.s3.transfer.TransferManager;
|
||||
import com.amazonaws.services.s3.transfer.Upload;
|
||||
import com.rbkmoney.file.storage.FileData;
|
||||
import com.rbkmoney.file.storage.NewFileResult;
|
||||
import com.rbkmoney.file.storage.configuration.properties.StorageProperties;
|
||||
@ -135,7 +136,13 @@ public class AmazonS3StorageService implements StorageService {
|
||||
objectMetadata
|
||||
);
|
||||
putObjectRequest.setMetadata(object.getObjectMetadata());
|
||||
s3Client.putObject(putObjectRequest);
|
||||
|
||||
Upload upload = transferManager.upload(putObjectRequest);
|
||||
try {
|
||||
upload.waitForUploadResult();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
log.info(
|
||||
"File have been successfully uploaded, fileId='{}', bucketId='{}'",
|
||||
@ -339,11 +346,7 @@ public class AmazonS3StorageService implements StorageService {
|
||||
}
|
||||
|
||||
private String getFileId() {
|
||||
String fileId;
|
||||
do {
|
||||
fileId = UUID.randomUUID().toString();
|
||||
} while (s3Client.doesObjectExist(bucketName, fileId));
|
||||
return fileId;
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private void checkNullable(Object object, String fileId, String objectType) throws StorageFileNotFoundException {
|
||||
|
@ -2,9 +2,8 @@ server.port=@server.port@
|
||||
spring.application.name=@project.name@
|
||||
info.version=@project.version@
|
||||
info.stage=dev
|
||||
|
||||
spring.servlet.multipart.max-file-size=128KB
|
||||
spring.servlet.multipart.max-request-size=128KB
|
||||
spring.servlet.multipart.max-file-size=10MB
|
||||
spring.servlet.multipart.max-request-size=10MB
|
||||
spring.servlet.multipart.enabled=true
|
||||
storage.endpoint=localhost
|
||||
storage.signingRegion=RU
|
||||
|
Loading…
Reference in New Issue
Block a user