From 3f7fe6da0012ed3eaf45f72f0da78240d1b451dd Mon Sep 17 00:00:00 2001 From: GeoNetwork opensource <59019313+geonetworkbuild@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:43:37 +0100 Subject: [PATCH] Use the copyBlob to copy the resource with updated metadata (#8533) 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" Co-authored-by: Ian Allen --- .../api/records/attachments/JCloudStore.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java b/core/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java index 579704aff45..10c89045643 100644 --- a/core/src/main/java/org/fao/geonet/api/records/attachments/JCloudStore.java +++ b/core/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();