Skip to content

Commit

Permalink
Fix multipart upload issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Trishkin committed Feb 15, 2023
1 parent fe56140 commit 7a515eb
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
import java.util.List;

import org.dcm4chee.arc.storage.CacheInputStream;
import org.jclouds.azureblob.blobstore.AzureBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.MultipartPart;
import org.jclouds.blobstore.domain.MultipartUpload;
import org.jclouds.io.Payload;
import org.jclouds.io.payloads.InputStreamPayload;
import org.jclouds.blobstore.options.PutOptions;

/**
* @author Daniil Trishkin <kernel.pryanic@protonmail.com>
Expand Down Expand Up @@ -82,18 +82,17 @@ private Payload createPayload() {

private void uploadMultipleParts(BlobStoreContext context, InputStream in, String container, String storagePath)
throws IOException {
AzureBlobStore blobStore = (AzureBlobStore) context.getBlobStore();
Payload payload = createPayload();
Blob blob = blobStore.blobBuilder(storagePath).payload(payload).build();
MultipartUpload mpu = blobStore.initiateMultipartUpload(container, blob.getMetadata(), null);
BlobStore blobStore = context.getBlobStore();
Blob blob = blobStore.blobBuilder(storagePath).payload(createPayload()).build();
MultipartUpload mpu = blobStore.initiateMultipartUpload(container, blob.getMetadata(), new PutOptions().multipart());
List<MultipartPart> parts = new ArrayList<MultipartPart>();
int partNumber = 1;
do {
parts.add(blobStore.uploadMultipartPart(mpu, partNumber, payload));
parts.add(blobStore.uploadMultipartPart(mpu, partNumber, createPayload()));
partNumber++;
} while (fillBuffers(in));
if (available() > 0)
parts.add(blobStore.uploadMultipartPart(mpu, partNumber, payload));
parts.add(blobStore.uploadMultipartPart(mpu, partNumber, createPayload()));
blobStore.completeMultipartUpload(mpu, parts);
}
}

0 comments on commit 7a515eb

Please sign in to comment.