Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么CloudBlockBlob.DownloadToStream总是返回空流?_C#_Azure_Streaming_Azure Storage Blobs - Fatal编程技术网

C# 为什么CloudBlockBlob.DownloadToStream总是返回空流?

C# 为什么CloudBlockBlob.DownloadToStream总是返回空流?,c#,azure,streaming,azure-storage-blobs,C#,Azure,Streaming,Azure Storage Blobs,我有以下代码: public static void UploadStreamToBlob(Stream stream, string containerName, string blobName) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); Cl

我有以下代码:

public static void UploadStreamToBlob(Stream stream, string containerName, string blobName)
{
    CloudStorageAccount storageAccount = 
        CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

    CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName);
    blobContainer.CreateIfNotExists();
    blobContainer.SetPermissions(
        new BlobContainerPermissions
        {
            PublicAccess = BlobContainerPublicAccessType.Blob
        });

    CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(blobName);
    long streamlen = stream.Length;  <-- This shows 203 bytes
    blockBlob.UploadFromStream(stream);        
}
public static void UploadStreamToBlob(流、字符串containerName、字符串blobName)
{
CloudStorageAccount storageAccount=
解析(CloudConfigurationManager.GetSetting(“StorageConnectionString”);
CloudBlobClient blobClient=storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer=blobClient.GetContainerReference(containerName);
blobContainer.CreateIfNotExists();
blobContainer.SetPermissions(
新BlobContainerPermissions
{
PublicAccess=BlobContainerPublicAccessType.Blob
});
CloudBlockBlob blockBlob=blobContainer.getblockblobbreference(blobName);

long streamlen=stream.Length;啊,我算出来了

以下几行:

long streamlen = stream.Length;
blockBlob.UploadFromStream(stream);   
需要改成

long streamlen = stream.Length;  
stream.Position = 0;
blockBlob.UploadFromStream(stream);   

+1:刚刚帮我摆脱了一个空Blob下载场景…通常是简单的细节让我们绊倒。这是处理流时的常见问题。我将所有设置都设置为IO方法
stream.Seek(0,SeekOrigin.Begin);
long streamlen = stream.Length;  
stream.Position = 0;
blockBlob.UploadFromStream(stream);