Ejemplo n.º 1
0
        public async Task <ActionResult> Upload(HttpPostedFileBase image)
        {
            if (image != null && image.ContentLength > 0)
            {
                CloudBlobContainer container = asManager.generateOriginalImageContainer();
                CloudBlockBlob     blob      = container.GetBlockBlobReference(FileNameCorrector.makeValidFileName(image.FileName));
                if (blob.Exists())
                {
                    blob = container.GetBlockBlobReference(FileNameCorrector.makeValidFileName(Path.GetFileNameWithoutExtension(image.FileName) + Guid.NewGuid().ToString() + Path.GetExtension(image.FileName)));
                }
                await blob.UploadFromStreamAsync(image.InputStream);

                asManager.insertQueue(new MyImage()
                {
                    fileName  = FileNameCorrector.makeValidFileName(Path.GetFileName(image.FileName)),
                    height    = Constants.imageHeight,
                    width     = Constants.imageWidth,
                    timeStamp = DateTime.UtcNow,
                    Image     = (asManager.generateOriginalImageContainer()).ListBlobs().
                                First(p => p.Uri.ToString().Contains(FileNameCorrector.
                                                                     makeValidFileName(Path.GetFileName(image.FileName)))).Uri.ToString()
                });
            }
            return(RedirectToAction("Upload"));
        }