如何使用Azure Java Storage SDK V10获取Blob Uri

时间:2018-11-23 05:13:42

标签: java azure rx-java azure-storage azure-storage-blobs

我尝试关注azure storage Samples,并能够上传Blob。我正在尝试获取上传的Blob的Uri,但我无法获得Uri。

在以前的SDK v7中,我能够执行blobItem.getUri(),但在新版本中找不到它。我尝试了以下操作,但是元数据没有Uri,它实际上是属性。我如何获得Uri

    blobURL.upload(Flowable.just(ByteBuffer.wrap(image)), image.length, headers, mData, null, null)
    .flatMap(bulkBlockBlobUploadResponse -> {
        this.getContext().getLogger().info(bulkBlockBlobUploadResponse.headers().eTag());
        return Single.just(true);
    })
    .flatMap(response ->
        // Query the blob's properties and metadata.
        this.getBlockBlobURL().getProperties(null, null))
    .flatMap(blobGetPropertiesResponse -> { 
        this.getContext().getLogger().info(blobGetPropertiesResponse.headers().metadata().toString());
        return Single.just(true);
    })

2 个答案:

答案 0 :(得分:0)

这可能是由于sdk版本不同造成的,有示例可供参考。

static void getBlob(BlockBlobURL blobURL, File sourceFile) {
    try {
        // Get the blob using the low-level download method in BlockBlobURL type
        // com.microsoft.rest.v2.util.FlowableUtil is a static class that contains helpers to work with Flowable
        blobURL.download(new BlobRange(0, Long.MAX_VALUE), null, false)
        .flatMapCompletable(response -> {
            AsynchronousFileChannel channel = AsynchronousFileChannel.open(Paths
                .get(sourceFile.getPath()), StandardOpenOption.CREATE,  StandardOpenOption.WRITE);
                    return FlowableUtil.writeFile(response.body(), channel);
        }).doOnComplete(()-> System.out.println("The blob was downloaded to " + sourceFile.getAbsolutePath()))
        // To call it synchronously add .blockingAwait()
        .subscribe();
    } catch (Exception ex){
    System.out.println(ex.toString());
    }
}

您可以单击此link进行详细检查,希望对您有所帮助。

答案 1 :(得分:0)

回答得有点晚,但是在 BlockBlobURL 对象上,您具有 toURL()方法。 因此,仅需执行以下操作即可获取URI:

BlockBlobURL my_blob = ... // your call to obtain the BlockBlobURL
URI blob_uri = blob.toURL().toURI();