I am trying to download a .json
blob that I have stored in a container in the Azure Storage
using Newtonsoft.Json
to write it to an object.
I am doing this by calling:
(CloudBlockBlob) blob.DownloadToStream(stream);
However, instead of writing the stream to a file in the local app directory, I want to return the json object
doing Json(result)
This is what I have tried:
using (var stream = new MemoryStream())
{
blob.DownloadToStream(stream);
var serializer = new JsonSerializer();
using (var sr = new StreamReader(stream))
{
using (var jsonTextReader = new JsonTextReader(sr))
{
result = serializer.Deserialize(jsonTextReader);
}
}
}
At the end my jsonTextReader
variable is empty and the object null
What can I do to accomplish this?
Thank you
You can store JSON data in Oracle Database using columns whose data types are VARCHAR2 , CLOB , or BLOB .
The possibility to query information on blob storage and other sources easily with a Serverless Pool has many uses. One of them is ad-hoc analysis queries, and the UI feature to view the result in many different ways contributes even more to this.
In order to download an Azure BLOB Storage item by its URL, you need to instantiate a CloudBlockBlob yourself using the item's URL: var blob = new CloudBlockBlob(new Uri(pdfFileUrl), cloudStorageAccount. Credentials); This blob can then be downloaded with the code you originally posted.
Please reset the stream's position to 0
after reading the blob into the stream. So your code would be:
using (var stream = new MemoryStream())
{
blob.DownloadToStream(stream);
stream.Position = 0;//resetting stream's position to 0
var serializer = new JsonSerializer();
using (var sr = new StreamReader(stream))
{
using (var jsonTextReader = new JsonTextReader(sr))
{
var result = serializer.Deserialize(jsonTextReader);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With