Esempio n. 1
0
        public ImageInfo UploadFile(string filename, string prefix, HttpPostedFileBase file)
        {
            if (!string.IsNullOrWhiteSpace(prefix))
            {
                filename = string.Format("{0}/{1}", prefix, filename);
            }
            if (file.ContentType == "application/pdf" || file.ContentType == "application/doc")
            {
                filename = GetUniqueName(FileContainer, filename);

                var blob = FileContainer.GetBlockBlobReference(filename);
                blob.Properties.ContentType = file.ContentType;
                blob.UploadFromStream(file.InputStream);

                return(new ImageInfo
                {
                    Name = blob.Name,
                    ContentType = blob.Properties.ContentType,
                    Size = blob.Properties.Length,
                    Url = blob.Uri.ToString()
                });
            }
            else
            {
                filename = GetUniqueName(Container, filename);

                var blob = Container.GetBlockBlobReference(filename);
                blob.Properties.ContentType = "image/jpeg";
                blob.UploadFromStream(file.InputStream);

                return(new ImageInfo
                {
                    Name = blob.Name,
                    ContentType = blob.Properties.ContentType,
                    Size = blob.Properties.Length,
                    Url = blob.Uri.ToString()
                });
            }
        }