有些恐慌,我在这里不同意astaykov。我相信你可以使用ImageResizer和Azure,而不需要AzureReader2。也许我应该通过说'它适用于我的设置':)
我在MVC 3应用程序中使用ImageResizer。我有一个图像容器的标准Azure帐户。
下面是认为我的测试代码:
@using (Html.BeginForm("UploadPhoto", "BasicProfile", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}
而这里的中邮操作方法相应的代码:
// This action handles the form POST and the upload
[HttpPost]
public ActionResult UploadPhoto(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
string newGuid = Guid.NewGuid().ToString();
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("images");
// Retrieve reference to the blob we want to create
CloudBlockBlob blockBlob = container.GetBlockBlobReference(newGuid + ".jpg");
// Populate our blob with contents from the uploaded file.
using (var ms = new MemoryStream())
{
ImageResizer.ImageJob i = new ImageResizer.ImageJob(file.InputStream,
ms, new ImageResizer.ResizeSettings("width=800;height=600;format=jpg;mode=max"));
i.Build();
blockBlob.Properties.ContentType = "image/jpeg";
ms.Seek(0, SeekOrigin.Begin);
blockBlob.UploadFromStream(ms);
}
}
// redirect back to the index action to show the form once again
return RedirectToAction("UploadPhoto");
}
这是“粗略的”代码来测试理论和可以肯定会有所改进,但它在本地和Azure上部署时都可以工作。我还可以查看我上传的图片,这些图片的大小已正确调整。
希望这可以帮助别人。
“AzureReader2”插件负责为您提供所有Azure相关工作,但可以在不使用插件的情况下使用ImageResizer和Azure blob **只需遵循这些说明http:// www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/ –