【发布时间】:2018-06-11 10:54:42
【问题描述】:
我有一个将图像文件上传到 Azure Blob 存储的 C# Web 应用程序。我从文本框(没有文件上传控制器)传递图像文件的本地路径。此应用程序按预期在本地工作。但是当我在 Azure 上发布它时,它会抛出异常。
找不到文件(文件名)
应该进行哪些更改才能在 Azure 上运行它?
代码:
CloudBlobContainer container = Program.BlobUtilities.GetBlobClient.GetContainerReference(Container);// container
container.CreateIfNotExists();
container.SetPermissions(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
CloudBlobDirectory directory = container.GetDirectoryReference(foldername);
// Get reference to blob (binary content)
CloudBlockBlob blockBlob_image = directory.GetBlockBlobReference(imageid);
using (var filestream = System.IO.File.OpenRead(image_path))
{
blockBlob_image.UploadFromStream(filestream);
}
【问题讨论】:
-
您正试图通过指向您计算机上的文件来“上传”一个文件。因此,当您在您的计算机上 运行该网站时,它就会工作。如果您在其他地方运行网站,它将无法找到该文件。这不是上传,而是复制文件。实现正确上传到控制器。
-
我正在使用网络表单。不是mvc。此外,即使使用 FileUpload Control,它也会给出同样的错误
标签: c# file azure azure-storage azure-blob-storage