Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,25 @@ public DirectoryDownloadResponse toDirectoryDownloadResponse(CompletedDirectoryD
}

public UploadDirectoryRequest toUploadDirectoryRequest(DirectoryUploadRequest request) {
return UploadDirectoryRequest.builder()
UploadDirectoryRequest.Builder builder = UploadDirectoryRequest.builder()
.bucket(getBucket())
.source(Paths.get(request.getLocalSourceDirectory()))
.maxDepth(request.isIncludeSubFolders() ? Integer.MAX_VALUE : 1)
.s3Prefix(request.getPrefix())
.build();
.s3Prefix(request.getPrefix());

// Apply tags to all objects in the directory upload
if (request.getTags() != null && !request.getTags().isEmpty()) {
List<Tag> tags = request.getTags().entrySet().stream()
.map(entry -> Tag.builder().key(entry.getKey()).value(entry.getValue()).build())
.collect(Collectors.toList());
Tagging tagging = Tagging.builder().tagSet(tags).build();

// Use putObjectRequestTransformer to apply tags to each uploaded object
builder.putObjectRequestTransformer(putObjectRequestBuilder ->
putObjectRequestBuilder.tagging(tagging));
}

return builder.build();
}

public DirectoryUploadResponse toDirectoryUploadResponse(CompletedDirectoryUpload completedDirectoryUpload) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import lombok.Builder;
import lombok.Getter;

import java.util.Map;

import static java.util.Collections.unmodifiableMap;

/**
* Wrapper object for directory upload data
*/
Expand All @@ -12,4 +16,12 @@ public class DirectoryUploadRequest {
private final String localSourceDirectory;
private final String prefix;
private final boolean includeSubFolders;
/**
* (Optional parameter) The map of tagName to tagValue to be associated with all blobs in the directory
*/
private final Map<String, String> tags;

public Map<String, String> getTags() {
return tags == null ? Map.of() : unmodifiableMap(tags);
}
}
2 changes: 1 addition & 1 deletion blob/blob-gcp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.52.3</version>
<version>2.60.0</version>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,17 @@ protected DirectoryUploadResponse doUploadDirectory(DirectoryUploadRequest direc
// Generate blob key
String blobKey = transformer.toBlobKey(sourceDir, filePath, directoryUploadRequest.getPrefix());

// Upload file to GCS - use same approach as single file upload
com.google.cloud.storage.BlobInfo blobInfo = com.google.cloud.storage.BlobInfo.newBuilder(getBucket(), blobKey).build();
// Build metadata map with tags if provided
Map<String, String> metadata = new HashMap<>();
if (directoryUploadRequest.getTags() != null && !directoryUploadRequest.getTags().isEmpty()) {
directoryUploadRequest.getTags().forEach((tagName, tagValue) ->
metadata.put(TAG_PREFIX + tagName, tagValue));
}

// Upload file to GCS with tags applied
com.google.cloud.storage.BlobInfo blobInfo = com.google.cloud.storage.BlobInfo.newBuilder(getBucket(), blobKey)
.setMetadata(metadata.isEmpty() ? null : metadata)
.build();
storage.createFrom(blobInfo, filePath);
} catch (Exception e) {
failedUploads.add(FailedBlobUpload.builder()
Expand Down
Loading