From 8bfda7512d24c172111c8caf235815ef75bb9a0b Mon Sep 17 00:00:00 2001 From: Ian Allen Date: Tue, 3 Dec 2024 08:09:44 -0400 Subject: [PATCH] Use the copyBlob to copy the resource with updated metadata 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" --- .../api/records/attachments/JCloudStore.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java b/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java index 579704aff45..10c89045643 100644 --- a/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java +++ b/datastorages/jcloud/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java @@ -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 targetProperties = new HashMap<>(sourceBlob.getMetadata().getUserMetadata()); + Map targetProperties = new HashMap<>(blobMetadata.getUserMetadata()); // Check if target exists. StorageMetadata targetStorageMetadata = null; @@ -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();