Can't copy blob with Java API

Rob N 46 Reputation points
2020-10-02T20:41:10.403+00:00

I'm trying to get started with the Java API.

val blobServiceClient = BlobServiceClientBuilder().connectionString(connectStr).buildClient()
val containerClient = blobServiceClient.getBlobContainerClient("my-stuff")
val blobClient = containerClient.getBlobClient("Test1.txt")
val newBlobClient = containerClient.getBlobClient("Test2.txt")
newBlobClient.copyFromUrl(blobClient.blobUrl)

I get an error saying "The specified resource does not exist":

Exception in thread "main" com.azure.storage.blob.models.BlobStorageException: Status code 404, "<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>The specified resource does not exist.

But it does exist. I can download it; this works:

blobClient.downloadToFile("/Users/me/Desktop/foo.txt")
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,269 questions
0 comments No comments
{count} votes

Accepted answer
  1. deherman-MSFT 31,996 Reputation points Microsoft Employee
    2020-10-02T22:11:13.657+00:00

    @Rob N
    Please try attaching a SAS token with appropriate permissions to the copy source url. There is a recent GitHub thread where a user faced the same issue. Here is the code that worked for them:

    String sasToken = sourceBlobClient.generateSasToken();  
    copyBlobClient.copyFromUrl(sourceBlobClient.getBlobUrl() + "?" + sasToken);  
    

    Hope this helps. Let us know if you need further assistance or have further issues.

    --------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


0 additional answers

Sort by: Most helpful