【发布时间】:2019-09-15 17:40:57
【问题描述】:
我需要使用代理从 Azure blob 存储容器获取图像并将图像保存到 BufferedImage。
System.out.println("********Initiated******");
//Set Proxy Host name and Port
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("xx-xx-xxxxx", 8080));
OperationContext op = new OperationContext();
op.setProxy(proxy);
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container.
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference("images");
//call via this overload
Iterable<ListBlobItem> blobs = container.listBlobs(null, false, EnumSet.noneOf(BlobListingDetails.class), new BlobRequestOptions(), op);
URL urlOfImage = null;
//Listing contents of container
for(ListBlobItem blob: blobs) {
/*Process the Image. Sample URL from Azure: **https://someWebsite.blob.core.windows.net/images/00001.png***/
if(((CloudBlockBlob) blob).getName().toLowerCase().contains(".png")) {
urlOfImage = blob.getUri().toURL();
BufferedImage buffimage = ImageIO.read(urlOfImage);
}
}
System.out.println("********Success*********");
通过使用 URI,我可以通过浏览器(单独)打开图像。
问题:我想直接或通过 URI 处理 blob 内容。如果我在将图像保存到缓冲图像时运行上面的代码, 我收到以下错误。
Exception in thread "main" javax.imageio.IIOException: Can't get input stream from URL!
at javax.imageio.ImageIO.read(Unknown Source)
提前致谢。
【问题讨论】: