【问题标题】:asp.net - Upload to Windows Azure with FileUploadasp.net - 使用 FileUpload 上传到 Windows Azure
【发布时间】:2013-09-11 21:33:21
【问题描述】:

我从这里获得了使用 ASP.Net 在 Windows Azure 上上传 blob 文件的代码:

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

这段代码运行良好,但我需要的是在 ASP.Net 中使用 FileUpload 控件上传文件。我需要更改路径,并将其替换为 FileUpload 上文件的路径。但我在研究中发现 FileUpload 不会返回文件的完整路径。无论如何,文件的上传是由 FileUpload 完成的吗?我不知道如何使用 FileUpload 上传它。谁能帮帮我?

【问题讨论】:

标签: asp.net azure


【解决方案1】:

解决了我的问题:

我替换了代码

using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
    blockBlob.UploadFromStream(fileStream);
}

using (fileASP.PostedFile.InputStream)
{
blockBlob.UploadFromStream(fileASP.PostedFile.InputStream);
}

fileASPFileUpload 控件的 ID。现在可以正常使用了。

【讨论】:

    【解决方案2】:

    试试这个:

    if (FileUpload1.HasFile)
    {
        blockBlob.Properties.ContentType = FileUpload1.PostedFile.ContentType;
        blockBlob.UploadFromStream(FileUpload1.FileContent);
    }
    

    【讨论】:

      【解决方案3】:

      您的解决方案中缺少一些细节。内容类型浮现在脑海中。 this question上有一个固溶体

      【讨论】:

        猜你喜欢
        • 2013-01-09
        • 1970-01-01
        • 1970-01-01
        • 2012-06-20
        • 2016-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多