Created
February 9, 2017 22:56
-
-
Save erbrito/0f10ac66c9774bb9c6b03daaf243a055 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
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