| | |
| | | import com.ard.common.config.OssConfiguration; |
| | | import com.ard.oss.model.CredentialsDTO; |
| | | import com.ard.oss.service.impl.OssServiceContext; |
| | | import com.ard.sample.common.model.ResponseResult; |
| | | import com.ard.sample.media.model.FileUploadDTO; |
| | | import com.ard.sample.utils.S3PutObjectResponse; |
| | | import io.minio.MinioClient; |
| | | import io.minio.PutObjectArgs; |
| | | import io.minio.credentials.StaticProvider; |
| | | import io.minio.errors.MinioException; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestHeader; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.security.InvalidKeyException; |
| | |
| | | * 适配 MinIO SDK 8.3.7 + 服务器 RELEASE.2024-08-03 |
| | | * 承接大疆 PUT 上传请求,中转上传到 MinIO HTTPS 接口 |
| | | */ |
| | | @Api(tags = "机场上传minio") |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/minioTransfer") // 根路径,匹配 Nginx 转发的 /dock/、/kmz/ 路径 |
| | |
| | | * @param contentType 文件 MIME 类型(默认二进制流,适配多种文件格式) |
| | | * @return S3 规范 XML 响应(返回给大疆,衔接后续流程) |
| | | */ |
| | | @ApiOperation("minio上传") |
| | | @PutMapping("/{bucketName}/{objectName}") |
| | | public ResponseEntity<S3PutObjectResponse> proxyUpload( |
| | | @PathVariable String bucketName, |
| | |
| | | @RequestHeader(value = "Content-Type", defaultValue = "application/octet-stream") String contentType |
| | | ) { |
| | | try { |
| | | log.info("开始中转上传文件到 MinIO,收到参数:bucketName={}, objectName={}",bucketName,objectName); |
| | | // 步骤 1:获取 MinIO HTTPS 临时凭证(复用你的已有工具类,已验证可行) |
| | | CredentialsDTO credentials = ossService.getCredentials(); |
| | | if (credentials == null || credentials.getAccessKeyId() == null || credentials.getSecurityToken() == null) { |
| | |
| | | .contentType(contentType) // 文件 MIME 类型 |
| | | .build() |
| | | ); |
| | | log.info("文件上传成功,文件名:{}",objectName); |
| | | |
| | | // 步骤 4:构造符合 S3 规范的成功响应(返回给大疆,确保流程衔接) |
| | | S3PutObjectResponse successResponse = new S3PutObjectResponse( |
| | |
| | | // LastModified:当前时间(ISO 格式,MinIO 服务器兼容该格式) |
| | | OffsetDateTime.now().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) |
| | | ); |
| | | log.info("构造回复大疆机场的响应信息-S3PutObjectResponse:{}",successResponse); |
| | | |
| | | // 步骤 5:返回 200 OK + XML 格式响应(Spring Boot 自动转换实体类为 XML) |
| | | return ResponseEntity.status(HttpStatus.OK) |
| | |
| | | return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("测试") |
| | | @PostMapping("/test") |
| | | public ResponseResult fastUpload() { |
| | | return ResponseResult.success(); |
| | | } |
| | | } |