Skip to content

Instantly share code, notes, and snippets.

@bkjam
bkjam / FileDownloadNginxLuaPart1.conf
Created April 22, 2024 17:22
Download Service Nginx.conf
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;;";
@bkjam
bkjam / MinioFileDownloadUrlService.kts
Last active April 22, 2024 16:59
Generate Download Url
@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)
}
@bkjam
bkjam / MinioFileDownloadController2.kts
Created April 22, 2024 14:20
Generate Download Url
@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)
}
@bkjam
bkjam / MinioFileDownloadPresginedUrl.kts
Last active April 19, 2024 13:27
Minio File Download using Presigned Url
@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)
@bkjam
bkjam / MinioFileDownloadMultipleFile.kts
Last active April 19, 2024 03:02
Minio File Download for Multiple Files
@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\"")
@bkjam
bkjam / MinioFileDownloadSingleFile.kts
Last active April 22, 2024 13:13
Minio File Download for Single File
@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)
@bkjam
bkjam / MinioFileDownloadController.kts
Created April 19, 2024 02:20
File Download Controller for Minio
@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")
@bkjam
bkjam / minio-single-node-docker-compose.yaml
Created April 19, 2024 02:04
Minio Single Node Docker Compose
# 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
@bkjam
bkjam / minioClientConfig.kts
Created April 19, 2024 02:00
Minio Client Configuration
@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()
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.example.data.config.ReactiveMongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration