通过ASP.NET网页将文件上传到Azure存储 [英] File Uploading to Azure Storage by ASP.NET Webpages

查看:162
本文介绍了通过ASP.NET网页将文件上传到Azure存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些关于通过ASP.NET MVC将文件上传到Azure的参考,但是我在ASP.NET网页的字段中找不到任何参考文件

There are some reference about File Uploading to Azure BY ASP.NET MVC but I can't find none in field of ASP.NET Webpages

如何实现这样的功能代码上传到Azure存储?

How to implement such code to upload to Azure Storage?

嗯。有关更多信息,

我的目标是在CK编辑器中上传图像

My goal is image uploading in CK Editor

但是由于Azure托管,普通CKEditor参考无法正常工作。

but Due to Azure Hosting, ordinary CKEditor reference is not working.

所以我用Google搜索并使用了此代码块

So I googled and use this code block

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("lawimage");

// 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(name))
{
    blockBlob.UploadFromStream(fileStream);
}

但它不起作用,

和我的'web.config'是

and my 'web.config' is

<appSettings>
    <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=lawcbt;AccountKey=[MyAccountKey]/>
</appSettings>

有没有人通过ASP.NET WebPages上传到Azure存储?

Is anyone ever did upload to Azure Storage via ASP.NET WebPages?

PS>更清楚地说,我的 upload.aspx源文件是

P.S> To be more clear, My 'upload.aspx' source file is this

upload.aspx

推荐答案

我已经解决了自己!通过使用Visual Studio,我发现了一个错误点。 !!

I have solved myself! By using Visual Studio, I found a bugging point. olleh!!

即使我不喜欢Visual Studio,Visual Studio还是一个非常强大的工具Tongue Out

Even though I don't like Visual Studio, Visual Studio is very powerful tool Tongue Out

此代码将起作用!

<%@ Import namespace="System.Configuration" %>
<%@ Import namespace="Microsoft.WindowsAzure" %>
<%@ Import namespace="Microsoft.WindowsAzure.Storage" %>
<%@ Import namespace="Microsoft.WindowsAzure.Storage.Auth" %>
<%@ Import namespace="Microsoft.WindowsAzure.Storage.Blob" %>

......

    HttpPostedFile theFile = HttpContext.Current.Request.Files[0];
    // Azure Upload 

    // Retrieve storage account from connection string.
    StorageCredentials sc = new StorageCredentials("[MyStorageName]", "[MyKey]");
    CloudStorageAccount storageAccount = new CloudStorageAccount(sc, false);

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

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

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

    // Create or overwrite the "myblob" blob with contents from a local file.
    using (var fileStream = theFile.InputStream)
    {
        blockBlob.UploadFromStream(fileStream);
    } 

 .....

这篇关于通过ASP.NET网页将文件上传到Azure存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆