Skip to content

Commit

Permalink
Use the copyBlob to copy the resource with updated metadata
Browse files Browse the repository at this point in the history
Prior it was trying to copy the payload which was buggy on large files and could produce the following error
    "Failed copy of resources: Incomplete output stream connecting to PUT"
  • Loading branch information
ianwallen committed Dec 3, 2024
1 parent 5e6f08f commit 8bfda75
Showing 1 changed file with 10 additions and 10 deletions.
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

0 comments on commit 8bfda75

Please sign in to comment.