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

[Backport 4.2.x] Use the copyBlob to copy the resource with updated metadata #8533

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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 @@ -610,10 +610,10 @@ public void copyResources(ServiceContext context, String sourceUuid, String targ
String sourceBlobName = sourceStorageMetadata.getName();
String targetBlobName = targetResourceTypeDir + sourceBlobName.substring(sourceResourceTypeDir.length());

Blob sourceBlob = jCloudConfiguration.getClient().getBlobStore().getBlob(jCloudConfiguration.getContainerName(), sourceBlobName);
BlobMetadata blobMetadata = jCloudConfiguration.getClient().getBlobStore().blobMetadata(jCloudConfiguration.getContainerName(), sourceBlobName);

// Copy existing properties.
Map<String, String> targetProperties = new HashMap<>(sourceBlob.getMetadata().getUserMetadata());
Map<String, String> targetProperties = new HashMap<>(blobMetadata.getUserMetadata());

// Check if target exists.
StorageMetadata targetStorageMetadata = null;
Expand Down Expand Up @@ -670,14 +670,14 @@ public void copyResources(ServiceContext context, String sourceUuid, String targ
targetProperties.get(versionPropertyName)));
}
}
Blob targetblob = jCloudConfiguration.getClient().getBlobStore().blobBuilder(targetBlobName)
.payload(sourceBlob.getPayload())
.contentLength(sourceBlob.getMetadata().getContentMetadata().getContentLength())
.userMetadata(targetProperties)
.build();

// Upload the Blob in multiple chunks to supports large files.
jCloudConfiguration.getClient().getBlobStore().putBlob(jCloudConfiguration.getContainerName(), targetblob, multipart());

// Use the copyBlob to copy the resource with updated metadata.
jCloudConfiguration.getClient().getBlobStore().copyBlob(
jCloudConfiguration.getContainerName(),
sourceBlobName,
jCloudConfiguration.getContainerName(),
targetBlobName,
CopyOptions.builder().userMetadata(targetProperties).build());
}
}
marker = page.getNextMarker();
Expand Down
Loading