如果将ImageResizer与Azure blob一起使用,我是否需要AzureReader2插件? [英] If using ImageResizer with Azure blobs do I need the AzureReader2 plugin?

查看:101
本文介绍了如果将ImageResizer与Azure blob一起使用,我是否需要AzureReader2插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个个人项目来管理俱乐部会员,该项目托管在免费的Azure软件包中(至少目前如此),部分是作为试用Azure的实验.创建他们的记录的一部分是添加照片,因此我有一个联系人卡片"视图,可让我查看他们的身份,来历以及照片.

I'm working on a personal project to manage users of my club, it's hosted on the free Azure package (for now at least), partly as an experiment to try out Azure. Part of creating their records is to add a photo, so I've got a Contact Card view that lets me see who they are, when they came and a photo.

我已经安装了 ImageResizer ,从相机调整10MP照片的大小并将其保存到文件系统真的很容易.在本地,但似乎对于Azure,我需要使用其Blobs上传图片到Windows Azure网站,这对我来说是新的. 有关ImageResizer的文档说,我需要使用AzureReader2才能与Azure blob一起使用不是免费的.它还在他们的最佳实践#5至

I have installed ImageResizer and it's really easy to resize the 10MP photos from my camera and save them to the file system locally, but it seems that for Azure I need to use their Blobs to Upload Pictures to Windows Azure Web Sites, and that's new to me. The documentation on ImageResizer says that I need to use AzureReader2 in order to work with Azure blobs but it isn't free. It also says in their best practices #5 to

使用动态调整大小,而不是预先调整图像大小.

Use dynamic resizing instead of pre-resizing your images.

这不是我在想的,在创建用户记录时,我将尺寸调整为300x300和75x75(用于缩略图).但是,如果我应该将完整尺寸的图像存储为斑点并在输出时动态调整大小,那么我可以使用标准方法来

Which is not what I was thinking, I was going to resize to 300x300 and 75x75 (for thumbnail) when creating the users record. But if I should be storing full size images as blobs and dynamically resizing on the way out then can I just use standard means to Upload a blob into a container to save it to Azure, then when I want to display the images use the ImageResizer and pass it each image to resize as required. That way not needing to use the AzureReader2, or have I misunderstood what it does / how it works?

还有其他方法可以考虑吗?

Is there another way to consider?

我还没有 实施裁剪,但是当我确定了如何正确地实际存储图像之后,接下来要解决的问题

I've not yet implemented cropping, but that's next to tackle when I've worked out how to actually store the images properly

推荐答案

由于有些恐惧,我在这里不同意astaykov.我相信您可以将ImageResizer与Azure一起使用,而无需AzureReader2.也许我应该说出它对我的设置有效":)

With some trepidation, I'm going to disagree with astaykov here. I believe you CAN use ImageResizer with Azure WITHOUT needing AzureReader2. Maybe I should qualify that by saying 'It works on my setup' :)

我正在MVC 3应用程序中使用ImageResizer.我有一个带有图片容器的标准Azure帐户.

I'm using ImageResizer in an MVC 3 application. I have a standard Azure account with an images container.

这是该视图的测试代码:

Here's my test code for the view:

@using (Html.BeginForm( "UploadPhoto", "BasicProfile", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="file" />
    <input type="submit" value="OK" />
}

这是Post Action方法中的相应代码:

And here's the corresponding code in the Post Action method:

// 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上部署时均有效.我还可以查看上传的图像,这些图像可以正确调整大小.

This is 'rough and ready' code to test the theory and could certainly stand improvement but, it does work both locally and when deployed on Azure. I can also view the images I've uploaded, which are correctly re-sized.

希望这对某人有帮助.

这篇关于如果将ImageResizer与Azure blob一起使用,我是否需要AzureReader2插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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