繁体   English   中英

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

[英]How to get blob Uri using azure Java Storage SDK V10

我试着按照天蓝色的存储示例,并能够上传Blob。 我正在尝试获取上传的Blob的Uri,但无法获取。

在以前的SDK v7中,我可以执行blobItem.getUri(),但在新版本中找不到它。 我尝试了以下操作,但是元数据没有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);
    })

这可能是由于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());
    }
}

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM