2016-03-02 40 views
0

大约有文件上传到Azure的BY ASP.NET MVC一些参考,但我无法找到没有在ASP.NET网页的领域文件上传到Azure存储由ASP.NET网页

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

嗯..欲了解更多信息,

我的目标是在CK编辑器

但由于Azure的托管图片上传,普通CKEditor的参考不工作。

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

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' 是

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

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

P.S>更清楚,我的“upload.aspx”源文件是这样的

upload.aspx

+0

您是否获得某种处理错误的?或者,对服务器的POST请求返回OK(200),但该文件不在容器上? –

+0

处理错误,我想要一些整体上传到Azure源的鸡尾酒由Asp.net网页 –

回答

0

当然,你必须首先把文件上传到你Asp.Net网页。从那里你可以上传到你的blobstorage。在你的代码中,似乎你正试图从服务器上传一个文件到blobstorage。首先,您必须将文件上传到服务器,然后才能将该流发送到blobstorage。

+0

写的好..问题是'传入blobstorage的流'不起作用。我想知道一些由ASP.net网页编写的源代码 –

0

我已经解决了我自己!通过使用Visual Studio,我发现了一个窃听点。 2009东海生日贺!

即使我不喜欢的Visual Studio,Visual Studio是非常强大的工具舌头

也许是heavyness值得了点。

此代码将工作!

<%@ 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); 
    } 

..... 
相关问题