多少の不安はありますが、私はここで astaykov に同意しません。AzureReader2 を必要とせずに、Azure で ImageResizer を使用できると思います。たぶん、「私のセットアップで動作する」と言って、それを修飾する必要があります:)
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" />
}
Post Action メソッドの対応するコードは次のとおりです。
// 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 にデプロイされた場合でも機能します。アップロードした画像を正しくサイズ変更して表示することもできます。
これが誰かに役立つことを願っています。