1

Requirement : I want to list blobs from container and then copy it to other storage account using azure java sdk version 12.0.6.

I am facing same issue with listBlob and beginCopy method. Since I am also using async client, the spring boot application runs and completes but I dont get any value in listBlob from container.

I have added onSuccess or OnCompletion callbacks , but it doesnt resolve my problem? I dont want to use sync clients, because I want to copy multiple files at a time, so dont want to block these operations.

I don't want to add System.readline() or Thread.Sleep() or foreach. Does any other way can help me?

I also want the list of all the copy blobs and its status. So by using BlobCopyInfo we can do it. But that is also empty.

What can be the best way to do these async operations?

This is how I am listing blobs and inside this I have added beginCopy method.

    container.listBlobs(options).subscribe(x -> {
    BlobAsyncClient desblobClient = destinationContainer.getBlobAsyncClient("test");
    desblobClient.copyFromUrl(sourceUrl.toString()).doOnSuccess(response -> 
    doSuccess(response)).doOnError(error -> fail.add("error")).subscribe();
});

How can I get all the result of copy status?

sar
  • 99
  • 9

1 Answers1

0

Regarding the issue, please refer to the following code

 BlobContainerAsyncClient sourceClient = new BlobContainerClientBuilder()
                .connectionString("")
                .containerName("test")
                .buildAsyncClient();

        BlobContainerAsyncClient desblobClient  = new BlobContainerClientBuilder()
                .connectionString("")
                 .containerName("test1")
                .buildAsyncClient();

        sourceClient.listBlobs().subscribe(blob -> {    

            BlobAsyncClient client =sourceClient.getBlobAsyncClient( blob.getName());
            BlobServiceSasSignatureValues sas = new BlobServiceSasSignatureValues(OffsetDateTime.now().plusHours(1),
                    BlobContainerSasPermission.parse("r"));
            String sasToken = client.generateSas(sas);
            String url= client.getBlobUrl()+"?"+sasToken.toString();
             BlobAsyncClient client1 =desblobClient  .getBlobAsyncClient( blob.getName());
            client1.beginCopy(url, Duration.ofSeconds(3))
                    .subscribe(response -> System.out.printf("Copy identifier: %s%n", response));


        });
Jim Xu
  • 21,610
  • 2
  • 19
  • 39
  • yes, this I already did. Infact, in your code you should use desblobClient, it is getting copied in source itself. My issue is, the application runs and no value comes up in listBlob. My application runs and their is no value in listBlob. What should I do to stop the application or keep it running. I used onSuccess/ OnError callbacks, but that also didnt work. – sar Apr 27 '20 at 05:45
  • @sar Sorry for my delay. We can use the code ` blobList.doOnNext(response -> System.out.println(response.getName())).blockLast();` to list blob : https://i.stack.imgur.com/gGhUB.png – Jim Xu Apr 30 '20 at 08:25
  • Hey @Jim Xu I tried this, but it slows down the application a lot. Also even if I implement this copy , I am not able to get the correct copy count. I have used onSuccess and OnError methods and i am incrementing the value. It gives me less number of copy count and when I see in azure portal, I can see file is copied – sar May 05 '20 at 18:33