I am using the below code to generating the ByteStream from the SasUrl of Azure storage
ConnectionProvider connectionProvider =
ConnectionProvider.builder("custom-connection-provider")
.maxConnections(200)
.pendingAcquireMaxCount(5000)
.build();
BlobClient blobClient = new BlobClientBuilder()
.endpoint(searchMultipleWrapper.getSasUrl().trim()) // IT IS MY VALID SAS URL
.httpClient(new NettyAsyncHttpClientBuilder()
.connectionProvider(connectionProvider)
.readTimeout(Duration.ofMinutes(10))
.writeTimeout(Duration.ofMinutes(10))
.responseTimeout(Duration.ofMinutes(10))
.build())
.retryOptions(new RequestRetryOptions(
RetryPolicyType.EXPONENTIAL,
5,
2,
null,
null,
null
))
.buildClient();
log.info("BlobClient Object check {} ", blobClient);
// Use try-with-resources to ensure InputStream is closed
try (InputStream inputStream = blobClient.openInputStream();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
// Transfer data from InputStream to ByteArrayOutputStream
inputStream.transferTo(byteArrayOutputStream);
// Convert to Base64
byte[] imageBytes = byteArrayOutputStream.toByteArray();
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
log.info("Base 64 : {} ", base64Image);
// Log the Base64 string (truncated for safety)
log.info("Base64 Image (truncated): " + base64Image.substring(0, Math.min(base64Image.length(), 100)) + "...");
} catch (Exception e) {
log.error("Error while processing blob content", e);
}
Exception which i am getting as below :-
stack_trace":"reactor.core.Exceptions$ReactiveException: ioty.channel.StacklessClosedChannelException\n\tat
Heading ##reactor.core.Exceptions.propagate(Exceptions.java:410)\n\tat
reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:102)\n\tat reactor.core.publisher.Mono.block(Mono.java:1779)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:393)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:323)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:312)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:299)\n
I think it is the versioning issue which has the bug on the Window system. Please check the reference of this one Click here
Please help me to short out from this problem
I am using the below code to generating the ByteStream from the SasUrl of Azure storage
ConnectionProvider connectionProvider =
ConnectionProvider.builder("custom-connection-provider")
.maxConnections(200)
.pendingAcquireMaxCount(5000)
.build();
BlobClient blobClient = new BlobClientBuilder()
.endpoint(searchMultipleWrapper.getSasUrl().trim()) // IT IS MY VALID SAS URL
.httpClient(new NettyAsyncHttpClientBuilder()
.connectionProvider(connectionProvider)
.readTimeout(Duration.ofMinutes(10))
.writeTimeout(Duration.ofMinutes(10))
.responseTimeout(Duration.ofMinutes(10))
.build())
.retryOptions(new RequestRetryOptions(
RetryPolicyType.EXPONENTIAL,
5,
2,
null,
null,
null
))
.buildClient();
log.info("BlobClient Object check {} ", blobClient);
// Use try-with-resources to ensure InputStream is closed
try (InputStream inputStream = blobClient.openInputStream();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
// Transfer data from InputStream to ByteArrayOutputStream
inputStream.transferTo(byteArrayOutputStream);
// Convert to Base64
byte[] imageBytes = byteArrayOutputStream.toByteArray();
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
log.info("Base 64 : {} ", base64Image);
// Log the Base64 string (truncated for safety)
log.info("Base64 Image (truncated): " + base64Image.substring(0, Math.min(base64Image.length(), 100)) + "...");
} catch (Exception e) {
log.error("Error while processing blob content", e);
}
Exception which i am getting as below :-
stack_trace":"reactor.core.Exceptions$ReactiveException: io.netty.channel.StacklessClosedChannelException\n\tat
Heading ##reactor.core.Exceptions.propagate(Exceptions.java:410)\n\tat
reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:102)\n\tat reactor.core.publisher.Mono.block(Mono.java:1779)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:393)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:323)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:312)\n\tat com.azure.storage.blob.specialized.BlobClientBase.openInputStream(BlobClientBase.java:299)\n
I think it is the versioning issue which has the bug on the Window system. Please check the reference of this one Click here
Please help me to short out from this problem
generating the ByteStream from the SasUrl of Azure storage
You can use the below code with proper version and with sas url to generate the ByteStream using Azure Java SDK.
Code:
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.storage.blob.BlobClient;
import com.azure.storage.blob.BlobClientBuilder;
import com.azure.storage.common.policy.RequestRetryOptions;
import com.azure.storage.common.policy.RetryPolicyType;
import reactor.netty.resources.ConnectionProvider;
import java.io.ByteArrayOutputStream;
import java.time.Duration;
import java.util.Base64;
public class App {
public static void main(String[] args) {
// Example SAS URL (replace with your actual SAS URL)
String sasUrl = "https://<Account name>.blob.core.windows.net/<Conatiner name>/<blob name>?sp=r&st=2025-01-24T03:07:42Z&se=2025-01-24T11:07:42Z&spr=https&sv=2022-11-02&sr=b&sig=redacted";
ConnectionProvider connectionProvider = ConnectionProvider.builder("custom-connection-provider")
.maxConnections(200) // Adjust as per your concurrency needs
.pendingAcquireMaxCount(5000)
.build();
BlobClient blobClient = new BlobClientBuilder()
.endpoint(sasUrl.trim())
.retryOptions(new RequestRetryOptions(
RetryPolicyType.EXPONENTIAL,
5,
2,
null,
null,
null
))
.httpClient(new NettyAsyncHttpClientBuilder()
.connectionProvider(connectionProvider)
.readTimeout(Duration.ofMinutes(10))
.writeTimeout(Duration.ofMinutes(10))
.responseTimeout(Duration.ofMinutes(10))
.build())
.buildClient();
System.out.println("BlobClient created successfully");
// Read blob content as a Base64-encoded string
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
// Download blob content into the output stream
blobClient.downloadStream(byteArrayOutputStream);
// Convert the downloaded bytes to Base64
byte[] imageBytes = byteArrayOutputStream.toByteArray();
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
// Log the Base64 string (truncated for safety)
System.out.println("Base64 Image (truncated): " +
base64Image.substring(0, Math.min(base64Image.length(), 100)) + "...");
} catch (Exception e) {
System.err.println("Error while processing blob content");
e.printStackTrace();
}
}
}
My versions are azure-storage-blob
is 12.29.0
and azure-core-http-netty
is 1.15.7
.
Output:
BlobClient created successfully
Base64 Image (truncated): /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAxxxxxxxxxxxxxxHBwcGBwcICQsJCAgKCAcHCg0KCgsM...
Reference: Download a blob with Java - Azure Storage | Microsoft Learn
As i have mentioned in the question that it might be an open issue from the dependency side
I have used the below dependency which works perfectly previously i was using the azure-storage-blob
artifactId which was casing the above-mentioned issue.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-okhttp</artifactId>
<version>1.12.0</version>
</dependency>
sas url
spr=https is misssing. – Venkatesan Commented Jan 24 at 5:15