Note that there are some explanatory texts on larger screens.

plurals
  1. POCloudBlob.OpenRead() is not reading all data
    primarykey
    data
    text
    <p>With windows Azure Storage Client Library, CloudBlob.OpenRead() method reads only 4 mb of data. How can I read full stream using OpenRead method.</p> <pre><code>CloudBlob blob = container.GetBlobReference(filename); Stream stream = blob.OpenRead(); </code></pre> <p>I must use OpenRead method. Can't use DownloadToFile or DownloadToStream.</p> <p><strong>EDIT :</strong> The consumer code which is outside my scope calls </p> <pre><code>stream.CopyTo(readIntoStream); </code></pre> <p>CopyTo is an extension method.</p> <pre><code>public static int CopyTo(this Stream source, Stream destination) { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; int bytesCopied = 0; do { bytesRead = source.Read(buffer, 0, BUFFER_SIZE); if (bytesRead &gt; 0) destination.Write(buffer, 0, bytesRead); bytesCopied += bytesRead; } while (bytesRead &gt; 0); return bytesCopied; } </code></pre> <p><strong>EDIT 2 :</strong></p> <p>I have observed that when file is uploaded using blob.UploadText() method, it works fine but when blob is uploaded using OpenWrite method as done in following code sample, the OpenRead Method reads only 4194304 bytes (4 mb).</p> <pre><code>using(var input = File.OpenRead(@"C:\testFile.txt")) //5000000 bytes using (var output = blob.OpenWrite()) { input.CopyTo(output); } </code></pre> <p><strong>EDIT 3 :</strong></p> <p>Complete code that produces the issue at my end.</p> <pre><code> static void Main(string[] args) { var blobContainer = GetContainer("tier1"); blobContainer.CreateIfNotExist(); var containerPermissions = new BlobContainerPermissions(); containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob; blobContainer.SetPermissions(containerPermissions); var blob = blobContainer.GetBlobReference("testfileWithOpenWrite1.txt"); using (var input = File.OpenRead(@"C:\testFile.txt")) //5000000 bytes using (var output = blob.OpenWrite(new BlobRequestOptions())) input.CopyTo(output); Console.WriteLine("uploaded"); int bytesDownloaded = 0; byte[] buffer = new byte[65536]; using (BlobStream bs = blob.OpenRead()) { int chunkLength; do { chunkLength = bs.Read(buffer, 0, buffer.Length); bytesDownloaded += chunkLength; } while (chunkLength &gt; 0); } Console.WriteLine(bytesDownloaded); } public static int CopyTo(this Stream source, Stream destination) { int BUFFER_SIZE = 65536; byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; int bytesCopied = 0; do { bytesRead = source.Read(buffer, 0, BUFFER_SIZE); if (bytesRead &gt; 0) destination.Write(buffer, 0, bytesRead); bytesCopied += bytesRead; } while (bytesRead &gt; 0); return bytesCopied; } </code></pre> <p><strong>EDIT 4 - Conclusion:</strong> </p> <p>This was probably a bug in Microsoft.WindowsAzure.StorageClient.dll (assembly version 6.0.6002.17043) that comes with SDK v1.2. It works with latest Microsoft.WindowsAzure.StorageClient.dll (assembly version 6.0.6002.18312 - SDK v1.4).</p> <p>Thanks smarx :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload