public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new ParseApi(configuration);

            try
            {
                var options = new ImagesOptions()
                {
                    FileInfo = new FileInfo
                    {
                        FilePath    = "slides/three-slides.pptx",
                        StorageName = Common.MyStorage
                    },
                    StartPageNumber     = 1,
                    CountPagesToExtract = 2
                };

                var request  = new ImagesRequest(options);
                var response = apiInstance.Images(request);
                foreach (var page in response.Pages)
                {
                    Console.WriteLine($"Images from {page.PageIndex} page.");
                    foreach (var image in page.Images)
                    {
                        Console.WriteLine($"Image path in storage: {image.Path}. Download url: {image.DownloadUrl}");
                        Console.WriteLine($"File format: {image.FileFormat}. Page index: {image.PageIndex}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling ParseApi: " + e.Message);
            }
        }
Beispiel #2
0
 public ImagesService(
     IOptions <ImagesOptions> imagesOptions,
     IImagesNamesService imagesNamesService,
     IHostingEnvironment env)
 {
     this.imagesOptions      = imagesOptions.Value;
     this.env                = env;
     this.imagesNamesService = imagesNamesService;
 }
 public UploadImagesController(
     IImagesService imagesService,
     IOptions <ImagesOptions> imagesOptions,
     IPersonalManager personalManager,
     IServiceProvider serviceProvider) : base(serviceProvider)
 {
     this.imagesService   = imagesService;
     this.imagesOptions   = imagesOptions.Value;
     this.personalManager = personalManager;
 }
Beispiel #4
0
        public void TestGetImage_FileNotFoundResult()
        {
            var testFile = TestFiles.NotExist;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message);
        }
Beispiel #5
0
        public void ImageExtractTest_Pdf_Container_FromPages_Error()
        {
            var testFile = TestFiles.Zip;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 1,
                CountPagesToExtract = 2
            };

            var request = new ImagesRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message);
        }
Beispiel #6
0
        public void ImageExtractTest_Pdf_FromPages_OutOfThePageRange()
        {
            var testFile = TestFiles.Pdf;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 3,
                CountPagesToExtract = 5
            };

            var request = new ImagesRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual("Request parameters missing or have incorrect format", ex.Message);
        }
Beispiel #7
0
        public void TestGetImage_IncorrectPassword()
        {
            var testFile = TestFiles.PasswordProtected;
            var options  = new ImagesOptions
            {
                FileInfo = new FileInfo {
                    FilePath = testFile.FullName, Password = "******"
                },
            };
            var request = new ImagesRequest(options);

            var ex = Assert.Throws <ApiException>(() => { ParseApi.Images(request); });

            Assert.AreEqual($"Password provided for file '{testFile.FullName}' is incorrect.", ex.Message);
        }
Beispiel #8
0
        public void TestGetImage_Docx()
        {
            var testFile = TestFiles.FourPages;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            int i = 0;

            foreach (var image in result.Images)
            {
                Assert.AreEqual($"parser/images/words/docx/four-pages_docx/image_{i}.jpeg", image.Path);
                Assert.NotNull(image.DownloadUrl);
                i++;
            }
        }
Beispiel #9
0
        public void TestGetImage_Pdf_FromPages()
        {
            var testFile = TestFiles.Pdf;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 1,
                CountPagesToExtract = 2
            };

            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Pages);
            Assert.AreEqual(2, result.Pages.Count);

            Assert.AreEqual("parser/images/pdf/template-document_pdf/page_1/image_0.jpeg", result.Pages[0].Images[0].Path);
            Assert.AreEqual("parser/images/pdf/template-document_pdf/page_2/image_0.jpeg", result.Pages[1].Images[0].Path);
        }
Beispiel #10
0
        public void TestGetImage_Email()
        {
            var testFile = TestFiles.ImageAndAttachment;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            var paths = new[]
            {
                "parser/images/email/eml/embedded-image-and-attachment_eml/",
            };

            foreach (var image in result.Images)
            {
                Assert.IsTrue(paths.Any(image.Path.Contains));
            }
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new ParseApi(configuration);

            try
            {
                var options = new ImagesOptions()
                {
                    FileInfo = new FileInfo
                    {
                        FilePath    = "pdf/PDF with attachements.pdf",
                        Password    = "******",
                        StorageName = Common.MyStorage
                    },
                    ContainerItemInfo = new ContainerItemInfo {
                        RelativePath = "template-document.pdf"
                    },
                    StartPageNumber     = 2,
                    CountPagesToExtract = 1
                };

                var request  = new ImagesRequest(options);
                var response = apiInstance.Images(request);
                foreach (var page in response.Pages)
                {
                    Console.WriteLine($"Images from {page.PageIndex} page.");
                    foreach (var image in page.Images)
                    {
                        Console.WriteLine($"Image path in storage: {image.Path}. Download url: {image.DownloadUrl}");
                        Console.WriteLine($"File format: {image.FileFormat}. Page index: {image.PageIndex}");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling ParseApi: " + e.Message);
            }
        }
Beispiel #12
0
        public void TestGetImage_Container()
        {
            var testFile = TestFiles.ZipWithEmailImagePdf;
            var options  = new ImagesOptions
            {
                FileInfo = testFile.ToFileInfo(),
            };
            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            var paths = new[]
            {
                "parser/images/containers/archive/zip-eml-jpg-pdf_zip/",
                "parser/images/containers/archive/zip-eml-jpg-pdf_zip/embedded-image-and-attachment_eml/",
                "parser/images/containers/archive/zip-eml-jpg-pdf_zip/template-document_pdf/"
            };

            foreach (var image in result.Images)
            {
                Assert.IsTrue(paths.Any(image.Path.Contains));
            }
        }
Beispiel #13
0
        public void ImageExtractTest_Pdf_ContainerItem_FromPages()
        {
            var testFile = TestFiles.PdfContainer;
            var options  = new ImagesOptions
            {
                FileInfo            = testFile.ToFileInfo(),
                StartPageNumber     = 1,
                CountPagesToExtract = 2,
                ContainerItemInfo   = new ContainerItemInfo {
                    RelativePath = "template-document.pdf"
                }
            };

            var request = new ImagesRequest(options);
            var result  = ParseApi.Images(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Pages);
            Assert.AreEqual(2, result.Pages.Count);

            Assert.AreEqual("parser/images/template-document_pdf/page_1/image_0.jpeg", result.Pages[0].Images[0].Path);
            Assert.AreEqual("parser/images/template-document_pdf/page_2/image_0.jpeg", result.Pages[1].Images[0].Path);
        }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImagesRequest"/> class.
 /// </summary>
 /// <param name="options">Extract image options.</param>
 public ImagesRequest(ImagesOptions options)
 {
     this.options = options;
 }