I have a class
public class TextCorpusFile
{
public int Id {get; set;}
public string FileType {get; set;}
public MemoryStream File {get; set;}
}
If I try to upload a file to Azure Blob Storage, the length of the file equals 0. ( the file was created, but length is 0)
public void SendTextCorpusFileData(TextCorpusFile textCorpusFile)
{
//get container by default
CloudBlobContainer textCorpusContainer =
ReturnTextCorpusFileContainer();
CloudBlockBlob blockBlob = textCorpusContainer.GetBlockBlobReference(textCorpusFile.Id + POINT + textCorpusFile.FileType);
blockBlob.UploadFromStream(textCorpusFile.File);
}
But if I send files by bytes, it works well and the length is not 0.
public void SendTextCorpusFileData(TextCorpusFile textCorpusFile)
{
//get by default
CloudBlobContainer textCorpusContainer =
ReturnTextCorpusFileContainer();
CloudBlockBlob blockBlob = textCorpusContainer.GetBlockBlobReference(textCorpusFile.Id + POINT + textCorpusFile.FileType);
blockBlob.UploadFromByteArray(textCorpusFile.File.ToArray(),
0,
(int)textCorpusFile.File.Length);
}
Why it works like this I can not understand (because UploadFromStream(Stream source and I am sure that MemoryStream : Stream)
Can you explain ?
Although none of the relevant code is shown I diagnose: The MemoryStream.Position
is at the end. This causes reads to return 0
bytes.
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