任何人都可以指导我如何在 Java SDK 中模拟 azure Blob 存储。
我想模拟连接字符串、SAS token 、端点、容器名称。如果这些都被mock了,那么mock BlobClient就很容易了。
引用代码是-
公共(public) BlobServiceClient blobServiceClient(){ 返回新的 BlobServiceClientBuilder().connectionString("测试字符串").buildClient(); }
最佳答案
要解决此问题,您可以在同一项目下的文件中使用各自的变量来保留连接字符串、SAS token 、端点、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://learn.microsoft.com/en-us/java/api/overview/azure/storage-blob-readme?view=azure-java-stable
关于java - 在 java SDK 中模拟 Azure 存储 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69159254/