如何从Azure Blob存储下载视频?

问题描述 投票:1回答:1

我试图从这样的Azure blob存储中下载视频。但每次下载时,文件都是空的。我通过将相同的文件上传到存储并检查它来测试它。当我检查blob文件的大小时,它在Azure存储中是空的。

        //Gets the folder and the particular video to upload to YouTube
        CloudBlobContainer videoscontainer = blobClient.GetContainerReference("videos");
        CloudBlob videofile = videoscontainer.GetBlobReference("test.mp4");

        MemoryStream videofileinmemory = new MemoryStream();
        await videofile.DownloadToStreamAsync(videofileinmemory);


       CloudBlobContainer container = blobClient.GetContainerReference("checkedvideos");
        //Create the container if it doesn't already exist.
        container.CreateIfNotExists();
        container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });

        CloudBlockBlob blockBlob = container.GetBlockBlobReference("sametestfile.mp4");
        blockBlob.UploadFromStream(videofileinmemory);
c# azure azure-storage-blobs
1个回答
1
投票

在azure blob存储上,没有文件类型。所以从其他blob下载.mp4 blob没有区别。

在您的情况下,您需要在上传blob之前重置videofileinmemory Position = 0。然后它应该工作。

videofileinmemory.Position = 0;
blockBlob.UploadFromStream(videofileinmemory);

如果我们想将blob从一个容器复制到另一个容器,则无需将blob下载到内存中。我们也可以使用CloudBlockBlob.StartCopy

 CloudBlockBlob videofile = videoscontainer.GetBlockBlobReference("test.mp4");
 CloudBlockBlob blockBlob = container.GetBlockBlobReference("sametestfile.mp4");
 blockBlob.StartCopy(videofile);
© www.soinside.com 2019 - 2024. All rights reserved.