Sim*_*tin 3 azure azure-storage-blobs imageresizer
我正在开发一个管理我俱乐部用户的个人项目,它托管在免费的Azure软件包上(至少目前为止),部分是作为尝试Azure的实验.创建他们的记录的一部分是添加一张照片,所以我有一个联系人卡片视图,让我可以看到他们是谁,他们来的时间和照片.
我已经安装了ImageResizer,它真的很容易从我的相机调整10MP的照片,并将它们保存到本地文件系统,但似乎为天青我需要使用他们Blobs来将图片上传到Windows Azure网站,这是新的我.ImageResizer上的文档说我需要使用AzureReader2才能使用Azure blob,但它不是免费的.它还在他们的最佳实践#5中说
使用动态调整大小而不是预先调整图像大小.
这不是我想的,在创建用户记录时,我将调整为300x300和75x75(缩略图).但是,如果我应该将全尺寸图像存储为blob并在出路时动态调整大小,那么我可以使用标准方法将blob上传到容器中以将其保存到Azure,然后当我想显示图像时使用ImageResizer和传递每个图像以根据需要调整大小.这种方式不需要使用AzureReader2,或者我误解了它的作用/它是如何工作的?
还有另一种方法可以考虑吗?
我没有尚未实现种植,但这是未来解决时,我已经计算出如何实际存储图像正确
Der*_*CST 11
有些惶恐,我在这里不同意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" />
}
Run Code Online (Sandbox Code Playgroud)
这是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");
}
Run Code Online (Sandbox Code Playgroud)
这是用于测试理论的"粗略且准备好"的代码,并且当然可以进行改进,但是它在本地和部署在Azure上时都能正常工作.我还可以查看我上传的图片,这些图片已正确调整大小.
希望这有助于某人.
| 归档时间: |
|
| 查看次数: |
3208 次 |
| 最近记录: |