简体   繁体   中英

How to get blob Uri using azure Java Storage SDK V10

I tried following azure storage Samples and am able to upload the blob. I am trying to get the Uri of the uploaded blob but I couldn't get the Uri.

In the previous SDK v7, I was able to do blobItem.getUri(), but couldn't find it in the new version. I tried the following, however the metadata doesn't have the Uri, its actually the properties. How do I get the 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);
    })

This is probably caused by the difference of the version of the sdk, there is a sample for reference.

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());
    }
}

You can click this link to check it in detail, hope it benefit.

Answer a little late but on the BlockBlobURL object you have a toURL() method. So to get the URI you just have to do :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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