Reputation: 292
I upload image and document file in Blob-Azure storage. I know,how to get the blob property(name,url ,etc) using java.
But My Problem :I Need get document file content.
my document content : The Azure Table storage service stores large amounts of structured data.
How to access the document content..
Thank u
Upvotes: 1
Views: 1929
Reputation: 55
Try this:
InputStream inputStream = null;
ObjectMapper objectMapper = new ObjectMapper();
BlobClient blobClient = blobContainerClient.getBlobClient(fileName);
if(blobClient == null || !blobClient.exists()) {
log.error("Blob not found or doesn't exist. Blob: {}", fileName);
throw new IllegalStateException("Blob not found or doesn't exist");
}
try{
inputStream = blobClient.openInputStream();
byte[] content = inputStream.readAllBytes();
return objectMapper.readValue(content, new TypeReference<>() { });
} catch (Exception e) {
log.error("Error occurred while downloading or parsing the blob. Blob: {}, Error: {}", fileName, e.getMessage());
log.debug("Stack trace: ", e);
//throw new custom exception;
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
log.error("Error occurred while closing InputStream for Blob: {}. Error: {}", fileName, e.getMessage());
log.debug("Stack trace: ", e);
//throw new custom exception;
}
}
}
Upvotes: 0
Reputation: 292
I got the solution for my problem. Here is the code.
BufferedReader br = new BufferedReader(new InputStreamReader(blob.openInputStream()));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
It may help someone.
Upvotes: 2
Reputation: 5523
I would suggest perhaps starting with: http://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to-use-blob-storage/
From there you'll find a deeper link on "How to: Download a Blob". This should hopefully get you where you need to go.
Upvotes: 0