azure - 如果我使用 MemoryStream,为什么 Azure UploadFromStream 不起作用(可以起作用,但长度等于 0)?

标签 azure stream arrays azure-storage azure-blob-storage

我有课

public class TextCorpusFile
{
    public int Id {get; set;}
    public string FileType {get; set;}
    public MemoryStream File {get; set;}
}

如果我尝试将文件上传到 Azure Blob 存储,文件的长度等于 0。(文件已创建,但长度为 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);

}

但是如果我按字节发送文件,效果很好,而且长度不为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);
}

为什么它会这样工作我无法理解(因为UploadFromStream(Stream源并且我确信MemoryStream:Stream)

你能解释一下吗?

最佳答案

虽然没有显示相关代码,但我诊断:MemoryStream.Position 位于末尾。这会导致读取返回 0 字节。

关于azure - 如果我使用 MemoryStream,为什么 Azure UploadFromStream 不起作用(可以起作用,但长度等于 0)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36306958/

相关文章:

asp.net - System.Diagnostics.TraceSource 未将数据发送到 Application Insights

Azure服务总线健康检查状态总是返回不健康

azure - Windows Azure 虚拟机静态 IP

xml - 流式传输 xml-conduit 解析结果

c++ - 与 CUDA 并行传输数组

azure - 如何配置 Azure Functions V3 以在本地运行时允许 50+MB 文件

canvas - 是否可以将流作为源添加到 html Canvas 元素作为 html 视频元素?

python - 如何分割大型 XBRL 文件?

Java - 创建与另一个二维数组大小相同的二维数组

c - 请帮助纠正此错误 : reading integers line by line from a file using fscanf in c