Not possible to make blob copy in Azure storage

Copper Contributor

Hello the community,

I have been looking for this since several days now, but I have no idea why i cannot make a simple Blob copy through my main program.
Hope this post will allow to resolve this issue, and help others too.

I am using azure-storage-blob version 12.10.2 in my Java project.

Here is the main program which detects the incoming file in the Azure blob storage and triggers the program :

 

 

 

  @FunctionName("Importer_QueueTrigger")
        @StorageAccount("AzureWebJobsStorage")
        public void queueHandler(
                @QueueTrigger(name = "message", queueName = "%AzureQueueName%", connection = "AzureWebJobsStorage") String message,
                @BindingName("DequeueCount") int dequeueNumber,
                final ExecutionContext context) {
    
     JsonObject jsonObject = new JsonParser().parse(message).getAsJsonObject();
            String subject = jsonObject.get("subject").getAsString();
            Path fileName = Paths.get(subject);
            String blobFileName = fileName.getFileName().toString();
    
            String accountKey="XXXXXXXXXX";
            String accountName="XXXXXXXXXX";
            String endPoint = "https://<domain>.blob.core.windows.net/";
            String sourceContainerName="workitems";
            String newBlobName="file_2_copied.xml";
    
            StorageSharedKeyCredential key = new StorageSharedKeyCredential(accountName, accountKey);
            BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
                    .credential(key)
                    .endpoint(endPoint)
                    .buildClient();
    
            BlobContainerClient sourceContainer = blobServiceClient.getBlobContainerClient(sourceContainerName);
            BlobContainerClient targetContainer = blobServiceClient.getBlobContainerClient(sourceContainerName);
            BlobClient sourceClient = sourceContainer.getBlobClient(name);
            BlobClient targetClient = targetContainer.getBlobClient(newBlobName);
    
            BlobSasPermission permissions = new BlobSasPermission();
            permissions.setReadPermission(Boolean.TRUE);
            BlobServiceSasSignatureValues signatureValues = new BlobServiceSasSignatureValues(OffsetDateTime.now().plusDays(1), permissions);
            String token = sourceClient.generateSas(signatureValues);
    
            BlobCopyFromUrlOptions options = new BlobCopyFromUrlOptions(sourceClient.getBlobUrl() + "?" + token);
            Response<String> res = targetClient.copyFromUrlWithResponse(options, Duration.ofDays(1), Context.NONE);
        }

 

 

 

 

This code is working fine in unit tests, but it looks blocked in the main program.
It seems there are various threads running in parallel. The main thread executing the copy looks locked by one of them ? 

When i debug the main program and I stop on the line making the blob copy, if i run my unit test to make blob copy, the unit test is well executed. I don't know why the main thread is blocked.

Have you any idea to resolve this situation ?

 

Laura.

 

0 Replies