Skip to content

Instantly share code, notes, and snippets.

@mand2
Created September 2, 2021 14:45
Show Gist options
  • Save mand2/3cae451b66ed8460ff46c531ab242a48 to your computer and use it in GitHub Desktop.
Save mand2/3cae451b66ed8460ff46c531ab242a48 to your computer and use it in GitHub Desktop.
@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