This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
error_log error.log info; | |
env DOWNLOAD_SERVICE_URL; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
lua_package_path "/path/to/lua-resty-redis/lib/?.lua;;"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
class UrlService( | |
private val redisTemplate: StringRedisTemplate, | |
private val uniqueIdGenerator: UniqueIdGenerator, | |
@Value("\${download.url}") private val downloadUrl: String | |
) { | |
companion object { | |
private val logger = LoggerFactory.getLogger(UrlService::class.java) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/api/v1/download") | |
class DownloadController( | |
private val storageService: StorageService, | |
private val urlService: UrlService | |
) { | |
companion object { | |
private val logger = LoggerFactory.getLogger(DownloadController::class.java) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
class StorageService( | |
private val minioClient: MinioClient, | |
@Value("\${object-storage.bucket}") private val bucket: String | |
) { | |
fun generatePresignedUrl(fileId: String): String? { | |
val args = GetPresignedObjectUrlArgs.builder() | |
.bucket(bucket) | |
.`object`(fileId) | |
.method(Method.GET) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
class StorageService( | |
private val minioClient: MinioClient, | |
@Value("\${object-storage.bucket}") private val bucket: String | |
) { | |
fun downloadMultipleFiles(fileIds: List<String>, response: HttpServletResponse) { | |
// Set Response Header | |
response.contentType = "application/zip"; | |
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"files.zip\"") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
class StorageService( | |
private val minioClient: MinioClient, | |
@Value("\${object-storage.bucket}") private val bucket: String | |
) { | |
fun downloadFile(fileId: String, response: HttpServletResponse) { | |
// Set File Content | |
val statArgs = StatObjectArgs.builder().bucket(bucket).`object`(fileId).build() | |
val stat = minioClient.statObject(statArgs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/api/v1/download") | |
class DownloadController(private val storageService: StorageService) { | |
companion object { | |
private val logger = LoggerFactory.getLogger(DownloadController::class.java) | |
} | |
@GetMapping | |
fun downloadFile(@RequestParam fileId: String, response: HttpServletResponse) { | |
logger.info("Received request to download file - $fileId") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# docker-compose.yaml | |
version: '3.7' | |
services: | |
minio: | |
container_name: minio_server | |
image: minio/minio:RELEASE.2024-04-18T19-09-19Z | |
ports: | |
- "9000:9000" # For connecting to Minio API | |
- "9001:9001" # For viewing Minio Web Console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
class MinioClientConfig( | |
@Value("\${object-storage.endpoint}") private val s3Endpoint: String, | |
@Value("\${object-storage.access-key}") private val accessKey: String, | |
@Value("\${object-storage.access-secret}") private val accessSecret: String | |
) { | |
@Bean | |
fun minioClient(): MinioClient { | |
try { | |
return MinioClient.builder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | |
com.example.data.config.ReactiveMongoAutoConfiguration,\ | |
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration |
NewerOlder