Пример #1
0
        public static string SaveUploadedImage(HttpPostedFile postedImage, ImageInformation imageInformation)
        {
            if (postedImage == null)
            {
                return(null);
            }

            string       fileName     = Guid.NewGuid().ToString() + Path.GetExtension(postedImage.FileName);
            ImageResizer imageResizer = new ImageResizer(imageInformation.Width, imageInformation.Height);

            using (var memoryStream = imageResizer.ResizeImage(postedImage.InputStream, Path.GetExtension(postedImage.FileName)))
            {
                //go back to start
                memoryStream.Seek(0, SeekOrigin.Begin);

                FileStorageManager.Instance.WriteToPublicContainer(
                    AppSettingsUtils.GetStringAppSetting("StorageConnectionString"),
                    AppSettingsUtils.GetStringAppSetting("StoragePublicContainerName"),
                    GetPhysicalFileName(imageInformation.BlobDirectoryName, fileName),
                    memoryStream);

                imageInformation.RelativeFileName = GetBlobRelativeFileName(AppSettingsUtils.GetStringAppSetting("StoragePrefixUrl"), imageInformation.BlobDirectoryName, fileName);
            }

            imageInformation.RelativeFileName = GetBlobRelativeFileName(AppSettingsUtils.GetStringAppSetting("StoragePrefixUrl"), imageInformation.BlobDirectoryName, fileName);

            return(fileName);
        }
Пример #2
0
        public static void ResizeFromStreamImage(string imageBlobFileName, string fileName, ImageInformation imageInformation)
        {
            using (var outputStream = FileStorageManager.Instance.ReadToPublicContainer(AppSettingsUtils.GetStringAppSetting("StorageConnectionString"), AppSettingsUtils.GetStringAppSetting("StoragePublicContainerName"), imageBlobFileName))
            {
                ImageResizer imageResizer = new ImageResizer(imageInformation.Width, imageInformation.Height);
                outputStream.Seek(0, SeekOrigin.Begin);

                using (var memoryStream = imageResizer.ResizeImage(outputStream, Path.GetExtension(fileName)))
                {
                    //go back to start
                    memoryStream.Seek(0, SeekOrigin.Begin);

                    FileStorageManager.Instance.WriteToPublicContainer(
                        AppSettingsUtils.GetStringAppSetting("StorageConnectionString"),
                        AppSettingsUtils.GetStringAppSetting("StoragePublicContainerName"),
                        GetPhysicalFileName(imageInformation.BlobDirectoryName, fileName),
                        memoryStream);

                    imageInformation.RelativeFileName = GetBlobRelativeFileName(AppSettingsUtils.GetStringAppSetting("StoragePrefixUrl"), imageInformation.BlobDirectoryName, fileName);
                }
            }
        }