If using ImageResizer with Azure blobs do I need the AzureReader2 plugin?

前端 未结 3 462
自闭症患者
自闭症患者 2021-01-14 10:33

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 c

相关标签:
3条回答
  • 2021-01-14 11:20

    You can also upload resized versions to azure. So, you first upload the original image as a blob, say with the name /original/xxx.jpg; then you create a resize of the image and upload that to azure with the name say /thumbnail/xxx.jpg. If you want to create the resized versions on the fly or on a separate thread, you may need to temporarily save the original to disk.

    0 讨论(0)
  • 2021-01-14 11:28

    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' :)

    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" />
    }
    

    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");
    }
    

    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.

    Hope this helps someone.

    0 讨论(0)
  • 2021-01-14 11:28

    The answer to the concrete question:

    If using ImageResizer with Azure blobs do I need the AzureReader2 plugin?

    is YES. And as described in the Image Resizer's documentation - that plugin is used to read/process/serve images out of Blob Storage. So there is no doubt - if you are going to use Image Resizer, AzureReader2 is your needed plugin to make things right. It will take care of Blob uploads/serve.

    Although I question Image Resizer's team competency on Windows Azure, since they are referencing Azure SDK v.2, while the most current version for Azure SDK is 1.8. What they mean is the Azure Storage Client Library, which has versions 1.7 and 2.x. Whereas version 2.x is recommended one to use and comes with Azure SDK 1.8. So, do not search for Azure SDK 2.0, install the latest one, which is 1.8. And by the way, use the Nuget Package Manager to install the Azure Storage Library v. 2.0.x.

    0 讨论(0)
提交回复
热议问题