public void Test_RecognizeAndTranslate_Get_2()
        {
            var    name        = "1168_016.3B.jpg";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";
            string srcPath     = Path.Combine(dataFolder, name);

            StorageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(srcPath));
            FileExistResponse resp = StorageApi.GetIsExist(storagePath, null, null);

            Assert.IsTrue(resp.FileExist.IsExist);

            var result = OcrApi.GetRecognizeAndTranslateToHtml(name, "en", "de", folder);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)result).Name));
        }
        public void Test_RecognizeAndTranslate_Get_2()
        {
            var    name        = "1168_016.3B.jpg";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";
            string srcPath     = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest  reqCr    = new PutCreateRequest(storagePath, fstr);
                UploadResponse    respUpl  = this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(storagePath);
                FileExistResponse resp     = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value);
            }
            var result = OcrApi.GetRecognizeAndTranslateToHtml(name, "en", "de", folder);

            Assert.IsNotNull(result);
            Assert.IsTrue(result is FileStream);
            Assert.IsTrue(File.Exists(((FileStream)result).Name));
        }
Example #3
0
        public void Run()
        {
            string srcName = "ocr_test_1.png";
            string folder  = "HtmlTestDoc";
            string storage = null;

            OcrApi ocrApi = new OcrApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            Stream stream = ocrApi.GetRecognizeAndTranslateToHtml(srcName, SrcLang, ResLang, folder, storage);

            if (stream != null && stream.GetType() == typeof(FileStream))
            {
                string name    = ((FileStream)stream).Name;
                string outPath = Path.Combine(CommonSettings.OutDirectory, Path.GetFileName(name));
                using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                {
                    stream.CopyTo(fstr);
                    fstr.Flush();
                    Console.WriteLine(string.Format("File '{0}' downloaded to: {1}", Path.GetFileName(name), outPath));
                }
            }
            stream.Close();
            stream.Dispose();
        }