【问题标题】:Azure blob Storage: Synchronous copy of block blobs across containers within the same Azure storage account is not workingAzure blob 存储:同一 Azure 存储帐户中跨容器的块 blob 同步副本不起作用
【发布时间】:2020-12-29 15:24:19
【问题描述】:

我正在使用 azure-storage java sdk 8.6.5 版中的 startCopy API 在同一存储帐户内的容器之间复制 blob。

String copyJobId = cloudBlockBlob.startCopy(srcBlob, srcBlob.getProperties().getContentMD5(), true,
                                            null, null, null, null)

我得到以下异常 -

[17:25:42.976] - [STDERR] com.microsoft.azure.storage.StorageException: The specified resource does not exist.
[17:25:42.977] - [STDERR]   at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:87)
[17:25:42.977] - [STDERR]   at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
[17:25:42.977] - [STDERR]   at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:196)
[17:25:42.978] - [STDERR]   at com.microsoft.azure.storage.blob.CloudBlob.startCopy(CloudBlob.java:791)
[17:25:42.978] - [STDERR]   at com.microsoft.azure.storage.blob.CloudBlockBlob.startCopy(CloudBlockBlob.java:302)
[17:25:42.978] - [STDERR]   at com.microsoft.azure.storage.blob.CloudBlockBlob.startCopy(CloudBlockBlob.java:252)

如果我在没有同步的情况下使用另一个 API,复制工作正常 -

String copyJobId = cloudBlockBlob.startCopy(srcBlob); //This works

知道我是否在这里遗漏了什么吗?

提前致谢!!!

编辑 - 使用@Bowman 的测试示例代码添加异常截图。

【问题讨论】:

  • 我已经发布了代码,看来同步复制对我来说没有问题。你可以看看有什么区别。

标签: azure-storage azure-blob-storage


【解决方案1】:

下面的代码在我这边可以正常工作:

import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
import com.microsoft.azure.storage.blob.CloudBlockBlob;


public class testbowman {

    public static void main(String[] args) throws Exception {
        String accountname = "0730bowmanwindow";
        String accountkey = "xxxxxx";
        String containername = "test";
        String source_blobname = "test1.txt";
        String sink_blobname = "test2.txt";
        StorageCredentials credentials = new StorageCredentialsAccountAndKey(accountname,accountkey);
        CloudStorageAccount account = new CloudStorageAccount(credentials);
        CloudBlobClient client = account.createCloudBlobClient();

        CloudBlobContainer container = client.getContainerReference(containername);;
        CloudBlockBlob source_cbb = container.getBlockBlobReference(source_blobname);
        CloudBlockBlob sink_cbb = container.getBlockBlobReference(sink_blobname);
        sink_cbb.startCopy(source_cbb,source_cbb.getProperties().getContentMD5(),true,null,null,null,null);
        System.out.println("This is a test.");
    }
}

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>testbowman</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>1.11</maven.compiler.source>
        <maven.compiler.target>1.11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-storage</artifactId>
            <version>8.6.5</version>
        </dependency>
    </dependencies>

</project>

这是我的存储配置:

同步成功复制:

你可以看看你和我有什么不同。(顺便说一句,startCopy(CloudBlockBlob sourceBlob) 也适用于我。)

【讨论】:

  • 非常感谢@Bowman 提供代码示例。这个带有syncCopy=true 的API 不适用于我的测试代码和你的相同的存储配置。我得到了同样的旧异常com.microsoft.azure.storage.StorageException: The specified resource does not exist.
  • @Arti 你已经准备好源文件了吗?代码真的很适合我,也许你可以把这个bug报告给MS,比如在Github上发布这个问题。
  • 我使用了与您添加的相同代码作为上面的屏幕截图。而且我还更改了存储帐户配置以匹配您所拥有的。我也会在 Github 上发布这个问题。
  • @Arti 太棒了!有任何更新请告诉我。:)
猜你喜欢
  • 1970-01-01
  • 2022-11-11
  • 2019-03-08
  • 2016-03-28
  • 2021-11-20
  • 2019-09-26
  • 2022-01-06
  • 2019-04-06
  • 2016-09-21
相关资源
最近更新 更多