Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting metadata and retention with UploadDirectoryRequest #5272

Closed
2 tasks
Se7enShawn opened this issue Jun 6, 2024 · 1 comment
Closed
2 tasks

Setting metadata and retention with UploadDirectoryRequest #5272

Se7enShawn opened this issue Jun 6, 2024 · 1 comment
Assignees
Labels
closed-for-staleness feature-request A feature should be added or improved.

Comments

@Se7enShawn
Copy link

Se7enShawn commented Jun 6, 2024

Describe the feature

I need set tagging, metadata and retention when uploading a directory with transfer manager

Use Case

This code not work, because applyMutation work on a new putObjectRequest and not on the builder autogenerated by the UploadDirectoryRequest

UploadDirectoryRequest uploadDirectoryRequest = UploadDirectoryRequest.builder()
  .source(sourceDirectory)
  .bucket(bucketName)
  .s3Prefix(prefix)
  .uploadFileRequestTransformer(request -> request
		.putObjectRequest(porb -> porb
			    .applyMutation(builder -> builder
			                .tagging(Tagging.builder().tagSet(tags).build())
			                .metadata(metadata)
			                .objectLockLegalHoldStatus(ObjectLockLegalHoldStatus.ON)
			                .objectLockMode(ObjectLockMode.COMPLIANCE)
			                .objectLockRetainUntilDate(retention)))
		  .addTransferListener(LoggingTransferListener.create()))
  .build();

Proposed Solution

Add a method putObjectRequestTransformer on UploadDirectoryRequest and/or update UploadDirectoryHelper to work correctly with mutation.
Currently UploadDirectoryHelper build PutObjectRequest before uploadFileRequestTransformer:

PutObjectRequest putObjectRequest = PutObjectRequest.builder()
  .bucket(uploadDirectoryRequest.bucket())
  .key(key)
  .build();

UploadFileRequest.Builder requestBuilder = UploadFileRequest.builder()
  .source(path)
  .putObjectRequest(putObjectRequest);

uploadDirectoryRequest.uploadFileRequestTransformer().accept(requestBuilder);

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Java SDK version used

2.25.64

JDK version used

openjdk version "17.0.11" 2024-04-16 LTS

Operating System and version

Windows 11

@Se7enShawn Se7enShawn added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 6, 2024
@Se7enShawn Se7enShawn changed the title Impossible to applyMutation on putObjectRequest during uploadDirectory Setting metadata and retention with UploadDirectoryRequest Jun 12, 2024
@debora-ito
Copy link
Member

@Se7enShawn the following example should work:

        DirectoryUpload upload = s3TransferManager.uploadDirectory(
            UploadDirectoryRequest.builder()
                .source(Paths.get("/Users/me/sourceDirectory"))
                .bucket(BUCKET)
                .s3Prefix(PREFIX)
                .s3Delimiter(DELIMITER)
                .uploadFileRequestTransformer(uftransformer -> {
                    var originalRequest = uftransformer.build().putObjectRequest();
                    
                    uftransformer.putObjectRequest(r -> r.bucket(originalRequest.bucket())
                                    .key(originalRequest.key())
                                    .tagging(Tagging.builder().tagSet(t->t.key("myTag").value("123")).build())
                                    .metadata(Map.of("foo", "metafoo"))
                                    .objectLockMode(ObjectLockMode.COMPLIANCE)
                                    .objectLockLegalHoldStatus(ObjectLockLegalHoldStatus.ON)
                                    .objectLockRetainUntilDate(retention))
                            .build();
                })
                .build()
        );

Let us know if you have follow-up questions.

@debora-ito debora-ito added closing-soon This issue will close in 4 days unless further comments are made. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 7, 2024
@debora-ito debora-ito self-assigned this Aug 7, 2024
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will close in 4 days unless further comments are made. labels Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

2 participants