Skip to content

Instantly share code, notes, and snippets.

@erbrito
Created February 9, 2017 22:56
Show Gist options
  • Save erbrito/0f10ac66c9774bb9c6b03daaf243a055 to your computer and use it in GitHub Desktop.
Save erbrito/0f10ac66c9774bb9c6b03daaf243a055 to your computer and use it in GitHub Desktop.
import com.amazonaws.auth.SystemPropertiesCredentialsProvider
import com.amazonaws.services.s3.model.ObjectMetadata
import com.amazonaws.services.s3.model.ObjectTagging
import com.amazonaws.services.s3.model.Tag
import com.amazonaws.services.s3.transfer.MultipleFileUpload
import com.amazonaws.services.s3.transfer.ObjectMetadataProvider
import com.amazonaws.services.s3.transfer.ObjectTaggingProvider
import com.amazonaws.services.s3.transfer.TransferManagerWithTagging
import com.amazonaws.services.s3.transfer.TransferProgress
class S3FolderMigrationClientWithTagging {
def loadMultipleFiles = { String directoryName ->
ObjectTaggingProvider taggingProvider = new ObjectTaggingProvider() {
ObjectTagging provideObjectTags(File file){
List<Tag> tagList = new ArrayList<Tag>()
tagList.add(new Tag(‘costCenter', costCenterName))
tagList.add(new Tag(‘client', clientName))
new ObjectTagging(tagList)
}
}
File directory = new File("./${directoryName}" )
if(!directory.isDirectory()){
directory.mkdir()
}
MultipleFileUpload multipleFileUpload = transferManager.uploadDirectory(bucketName, contextName, directory, false, metadataProvider, taggingProvider)
TransferProgress transferProgress = multipleFileUpload.progress
while (!multipleFileUpload.done){
Thread.sleep(1000)
}
directory.delete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment