【问题标题】:Mock Azure Storage Blob in java SDK在 Java SDK 中模拟 Azure 存储 Blob
【发布时间】:2021-11-08 13:03:23
【问题描述】:

谁能指导我如何在 Java SDK 中模拟 azure Blob Storage。

我想模拟连接字符串、SAS 令牌、端点、容器名称。如果所有这些都被模拟了,那么模拟 BlobClient 就很容易了。

参考代码是-

公共 BlobServiceClient blobServiceClient(){ return new BlobServiceClientBuilder().connectionString("TESTING STRING").buildClient(); }

【问题讨论】:

标签: java azure azure-blob-storage


【解决方案1】:

要解决此问题,您可以使用它们各自的变量将连接字符串、SAS 令牌、端点、ContainerName 的值保留在同一项目下的文件中。 您可以通过在代码中传递上述对象来使用以下语句模拟 blobClient。

BlobClient blobClient = new BlobClientBuilder()
    .endpoint("<your-storage-account-url>")
    .sasToken("<your-sasToken>")
    .containerName("mycontainer")
    .blobName("myblob")
    .buildClient();

// Only one "?" is needed here. If the sastoken starts with "?", please removing one "?".
BlobClient blobClient = new BlobClientBuilder()
    .endpoint("<your-storage-account-url>" + "/" + "mycontainer" + "/" + "myblob" + "?" + "<your-sasToken>")
    .buildClient();

参考:https://docs.microsoft.com/en-us/java/api/overview/azure/storage-blob-readme?view=azure-java-stable

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-04
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 2013-04-08
    • 2015-06-20
    相关资源
    最近更新 更多