Esempio n. 1
0
        public static AzureStorageModel GetBlobDirectoryList(string directoryName)
        {
            AzureStorage       storageClient     = AzureStorage.Instance;
            AzureStorageModel  azureStorageModel = new AzureStorageModel();
            CloudBlobDirectory directory         = storageClient.Container.GetDirectoryReference(directoryName);

            azureStorageModel.Container = storageClient.Container;
            azureStorageModel.IblobList = directory.ListBlobs().ToList();
            return(azureStorageModel);
        }
        public static List <CloudBlockBlob> ExtractImageUploadToAzure(PdfReader pdfReader, Stream blob, TraceWriter log, string name, ResumeDocModel resumeDocModel)
        {
            RandomAccessFileOrArray raf               = new RandomAccessFileOrArray(blob);
            List <CloudBlockBlob>   cloudBlockBlobs   = new List <CloudBlockBlob>();
            AzureStorageModel       azureStorageModel = AzStorage.GetBlobDirectoryList(name);

            if (azureStorageModel.IblobList.Count() > 0)
            {
                foreach (IListBlobItem listBlobItem in azureStorageModel.IblobList)
                {
                    CloudBlockBlob cloudBlob = listBlobItem as CloudBlockBlob;
                    cloudBlob.DeleteIfExists();
                }
            }
            try
            {
                for (int pageNumber = 1; pageNumber <= pdfReader.NumberOfPages; pageNumber++)
                {
                    PdfDictionary     pg          = pdfReader.GetPageN(pageNumber);
                    List <Image>      IlistImages = GetImagesFromPdfDict(pg, pdfReader);
                    EncoderParameters parms       = new EncoderParameters(1);
                    parms.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);
                    var encoder = ImageCodecInfo.GetImageEncoders().First(c => c.FormatID == ImageFormat.Jpeg.Guid);
                    foreach (Image image in IlistImages)
                    {
                        MemoryStream   ms        = new MemoryStream();
                        CloudBlockBlob cloudBlob = azureStorageModel.Container.GetBlockBlobReference(name + "/" + Guid.NewGuid() + ".jpeg");
                        image.Save(ms, encoder, parms);
                        ms.Seek(0, SeekOrigin.Begin); // otherwise you'll get zero byte files
                        cloudBlob.UploadFromStream(ms);
                        cloudBlockBlobs.Add(cloudBlob);
                        resumeDocModel.imageDetails.imageURLList.Add(cloudBlob.Uri.ToString());
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                pdfReader.Close();
            }
            return(cloudBlockBlobs);
        }