Created
September 2, 2021 14:45
-
-
Save mand2/3cae451b66ed8460ff46c531ab242a48 to your computer and use it in GitHub Desktop.
This file contains 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
@JvmField val pathRegEx: Regex = Regex("^(/)|(/)$") | |
fun uploadDirectoryOfClient(s3DirectoryClient:TransferManager, defaultPath: String) { | |
// 로컬 디렉토리 세팅 | |
val localPath = "/d/test/uploader/" | |
val localDirectory = File(localPath) | |
// s3 객체 경로 세팅 | |
val bucketName = "mand2" | |
val s3Path = pathRegEx.replace(defaultPath, "") | |
val s3UploadPath = "$s3Path/upload/210831" | |
try { | |
// 실제 업로드 | |
val uploadDirectory: MultipleFileUpload = s3DirectoryClient.uploadDirectory( | |
bucketName, | |
s3UploadPath, | |
localDirectory, | |
true | |
) | |
uploadDirectory.waitForCompletion() | |
logger.info("[Uploader] Upload Directory to S3 Success !") | |
} catch (e: AmazonServiceException) { | |
logger.error("Amazon service error: {}, {}", e.message, e) | |
} catch (e: AmazonClientException) { | |
logger.error("Amazon client error: {}, {}", e.message, e) | |
} catch (e: InterruptedException) { | |
logger.error("Transfer interrupted: {}, {}", e.message, e) | |
} finally { | |
s3DirectoryClient.shutdownNow() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment