locked
An exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code RRS feed

  • Question

  • using ImageResizer;
    using intellipix.Models;
    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Blob;
    using System.Configuration;
    using System.Threading.Tasks;
    using System.IO;
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace intellipix.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                // Pass a list of blob URIs in ViewBag
                CloudStorageAccount account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
                CloudBlobClient client = account.CreateCloudBlobClient();
                CloudBlobContainer container = client.GetContainerReference("photos");
                List<BlobInfo> blobs = new List<BlobInfo>();
    
                foreach (IListBlobItem item in container.ListBlobs())
                {
                    var blob = item as CloudBlockBlob;
    
                    if (blob != null)
                    {
                        blobs.Add(new BlobInfo()
                        {
                            ImageUri = blob.Uri.ToString(),
                            ThumbnailUri = blob.Uri.ToString().Replace("/photos/", "/thumbnails/")
                        });
                    }
                }
    
                ViewBag.Blobs = blobs.ToArray();
                return View();
            }
    
            public ActionResult About()
            {
                ViewBag.Message = "Your application description page.";
    
                return View();
            }
    
            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";
    
                return View();
            }
    
            [HttpPost]
            public async Task<ActionResult> Upload(HttpPostedFileBase file)
            {
                if (file != null && file.ContentLength > 0)
                {
                    // Make sure the user selected an image file
                    if (!file.ContentType.StartsWith("image"))
                    {
                        TempData["Message"] = "Only image files may be uploaded";
                    }
                    else
                    {
                        try
                        {
                            // Save the original image in the "photos" container
                            CloudStorageAccount account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
                            CloudBlobClient client = account.CreateCloudBlobClient();
                            CloudBlobContainer container = client.GetContainerReference("photos");
                            CloudBlockBlob photo = container.GetBlockBlobReference(Path.GetFileName(file.FileName));
                            await photo.UploadFromStreamAsync(file.InputStream);
    
                            // Generate a thumbnail and save it in the "thumbnails" container
                            using (var outputStream = new MemoryStream())
                            {
                                file.InputStream.Seek(0L, SeekOrigin.Begin);
                                var settings = new ResizeSettings { MaxWidth = 192 };
                                ImageBuilder.Current.Build(file.InputStream, outputStream, settings);
                                outputStream.Seek(0L, SeekOrigin.Begin);
                                container = client.GetContainerReference("thumbnails");
                                CloudBlockBlob thumbnail = container.GetBlockBlobReference(Path.GetFileName(file.FileName));
                                await thumbnail.UploadFromStreamAsync(outputStream);
                            }
                        }
                        catch (Exception ex)
                        {
                            // In case something goes wrong
                            TempData["Message"] = ex.Message;
                        }
                    }
                }
    
                return RedirectToAction("Index");
            }
        }
    }


    Monday, September 28, 2020 2:49 PM

Answers

All replies

  • Hi,

    Thank you for posting here.

    What's the type of your application?

    In order to help you find the correct forum to go ask questions, I have moved the thread to 'where is the forum for' forum.

    In addition, please describe your problem in detail. It will help others analyze your problem.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 29, 2020 1:22 AM
  • I'd try asking for help over here,

    https://docs.microsoft.com/en-us/answers/products/azure?product=all

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    • Proposed as answer by Guido Franzke Tuesday, September 29, 2020 5:41 AM
    • Marked as answer by Guido Franzke Monday, October 5, 2020 6:03 AM
    Tuesday, September 29, 2020 1:24 AM