Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java的Azure文件映像路径_Java_Spring_Azure_Azure Web App Service_Azure Storage - Fatal编程技术网

使用java的Azure文件映像路径

使用java的Azure文件映像路径,java,spring,azure,azure-web-app-service,azure-storage,Java,Spring,Azure,Azure Web App Service,Azure Storage,您好,我正在尝试在azure存储上保存图像,我已经有了配置步骤和上载方法 AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(sourceFile.toPath()); TransferManager.uploadFileToBlockBlob(fileChannel, blob, 8 * 1024 * 1024, null).subscribe(response -> { Syste

您好,我正在尝试在azure存储上保存图像,我已经有了配置步骤和上载方法

AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(sourceFile.toPath());
    TransferManager.uploadFileToBlockBlob(fileChannel, blob, 8 * 1024 * 1024, null).subscribe(response -> {
        System.out.println("Completed upload request.");
        System.out.println(response.response().statusCode());

    });

我如何在azure上获取url图像路径以将其保存在数据库中并显示在我的网站上?

正如@GauravMantri所说,您可以通过
blob.toURL()
获取blob的url。然后,如果blob的容器是公共的(设置为公共访问级别),并且blob的
ContentType
属性设置正确,如
image/png
,则可以通过url直接访问图像,例如在
img
标记中使用,以显示在下面的网页中

<img src="myaccountname.blob.core.windows.net/test/testURL">
您还可以在
blob.toURL()
的字符串末尾添加SAS签名


关于SAS签名,您可以在和中参考这些示例代码。

您可以编辑您的问题并在代码中包括如何创建
blob
对象吗?您可以尝试
blob.toURL()
方法获取blob的URL。@GauravMantri在blob.toURL()之后;我得到“”如何访问我的图像?
SharedKeyCredentials credentials = new SharedKeyCredentials(accountName, accountKey);
ServiceSASSignatureValues values = new ServiceSASSignatureValues()
                .withProtocol(SASProtocol.HTTPS_ONLY) // Users MUST use HTTPS (not HTTP).
                .withExpiryTime(OffsetDateTime.now().plusDays(2)) // 2 days before expiration.
                .withContainerName(containerName)
                .withBlobName(blobName);
BlobSASPermission permission = new BlobSASPermission()
                .withRead(true)
                .withAdd(true)
                .withWrite(true);
values.withPermissions(permission.toString());
SASQueryParameters serviceParams = values.generateSASQueryParameters(credentials);
String sasSign = serviceParams.encode();
String blobUrlWithSAS = String.format(Locale.ROOT, "https://%s.blob.core.windows.net/%s/%s%s",
                accountName, containerName, blobName, sasSign);
String blobUrlWithSAS = blob.toString()+sasSign;