Esempio n. 1
0
        private UploadResponse UploadPdfTemplate(string storageFileName, MemoryStream stream, StorageApi storageApi)
        {
            var createFileRequest = new PutCreateRequest(storageFileName, stream);
            var response          = storageApi.PutCreate(createFileRequest);

            return(response);
        }
        public void FilePutCreateTest()
        {
            var srcPath  = Path.Combine(TempFolderPath, "TestFolder1/TestFile1.data");
            var destPath = Path.Combine(TempFolderPath, "TestFolder2/TestFile1.data");

            //Get the file
            var file = DownloadFile(StorageName, srcPath);

            //PutCreate the file
            var request = new PutCreateRequest();

            request.Path      = destPath;
            request.File      = file;
            request.Storage   = DestStorageName;
            request.VersionId = null;
            var response = StorageApi.PutCreate(request);

            Assert.AreEqual(200, response.Code);

            //The file should exists on dest path
            var fileExist = FileExist(DestStorageName, destPath);

            Assert.IsTrue((bool)fileExist.IsExist);
            Assert.IsFalse((bool)fileExist.IsFolder);
        }
        public static bool uploadToStorage(string storagePath, string srcDir = null)
        {
            var           name        = Path.GetFileName(storagePath);
            Configuration storageConf = new Storage.Cloud.Sdk.Configuration()
            {
                ApiBaseUrl = CommonSettings.BasePath,
                AppKey     = CommonSettings.AppKey,
                AppSid     = CommonSettings.AppSID
            };
            StorageApi storageApi = new StorageApi(storageConf);
            // Upload source file to aspose cloud storage
            var srcPath = Path.Combine(srcDir ?? CommonSettings.DataFolder, name);

            if (File.Exists(srcPath))
            {
                using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
                {
                    var reqCr     = new PutCreateRequest(storagePath, fstr);
                    var respCr    = storageApi.PutCreate(reqCr);
                    var reqExist  = new GetIsExistRequest(storagePath);
                    var respExist = storageApi.GetIsExist(reqExist);

                    return(respExist.FileExist.IsExist.HasValue && respExist.FileExist.IsExist.Value);
                }
            }
            else
            {
                throw new Exception(string.Format("Error: file {0} not found.", srcPath));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Upload a specific file
        /// </summary>
        /// <param name="request">Request. <see cref="PutCreateRequest" /></param>
        /// <returns><see cref="UploadResponse"/></returns>
        public UploadResponse PutCreate(PutCreateRequest request)
        {
            // verify the required parameter 'path' is set
            if (request.Path == null)
            {
                throw new ApiException(400, "Missing required parameter 'path' when calling PutCreate");
            }

            // verify the required parameter 'file' is set
            if (request.File == null)
            {
                throw new ApiException(400, "Missing required parameter 'file' when calling PutCreate");
            }

            // create path and map variables
            var resourcePath = this.configuration.GetApiRootUrl() + "/storage/file";

            resourcePath = Regex
                           .Replace(resourcePath, "\\*", string.Empty)
                           .Replace("&amp;", "&")
                           .Replace("/?", "?");
            var formParams = new Dictionary <string, object>();

            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "path", request.Path);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.VersionId);
            resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storage", request.Storage);

            if (request.File != null)
            {
                formParams.Add("file", this.apiInvoker.ToFileInfo(request.File, "File"));
            }

            try
            {
                var response = this.apiInvoker.InvokeApi(
                    resourcePath,
                    "PUT",
                    null,
                    null,
                    formParams);
                if (response != null)
                {
                    return((UploadResponse)SerializationHelper.Deserialize(response, typeof(UploadResponse)));
                }

                return(null);
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode == 404)
                {
                    return(null);
                }

                throw;
            }
        }
Esempio n. 5
0
 private void Upload(string pdfPath, string filename, ResultsModel results)
 {
     using (var stream = new FileStream(pdfPath, FileMode.Open))
     {
         var storageApi = new StorageApi(_AppKey, _AppSid);
         var request    = new PutCreateRequest(filename, stream);
         results.uploadResponse = storageApi.PutCreate(request);
     }
 }
 public UploadResponse UploadPdf(string pdfPath, string fileName)
 {
     using (var stream = new FileStream(pdfPath, FileMode.Open))
     {
         var storageApi = new StorageApi(_apiKey, _appSid);
         var request    = new PutCreateRequest(fileName, stream);
         var actual     = storageApi.PutCreate(request);
         return(actual);
     }
 }
Esempio n. 7
0
        public UploadResponse UploadFile(string name, string pdfPath)
        {
            var storageApi = new StorageApi(_appKey, _appSID);

            using (var stream = new FileStream(pdfPath, FileMode.Open))
            {
                var request   = new PutCreateRequest(name, stream);
                var storeFile = storageApi.PutCreate(request);
                return(storeFile);
            }
        }
        public void SetUp()
        {
            #region Add folders

            try
            {
                for (var i = 1; i <= 2; i++)
                {
                    var request = new PutCreateFolderRequest();
                    request.Path        = string.Format("{0}/TestFolder{1}", TempFolderPath, i);
                    request.Storage     = StorageName;
                    request.DestStorage = DestStorageName;

                    var response = StorageApi.PutCreateFolder(request);
                    Assert.AreEqual(200, response.Code);
                }
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("not supported"), ex.Message);
            }

            #endregion

            #region Add files
            {
                var request = new PutCreateRequest()
                {
                    Storage = StorageName, VersionId = null
                };

                for (var i = 1; i <= 2; i++)
                {
                    //Add TestFile.data
                    request.File = new MemoryStream(new byte[] { 1, 2, 3, 4, 5, 6 });
                    request.Path = string.Format("{0}/TestFolder{1}/TestFile{1}.data", TempFolderPath, i);
                    var response = StorageApi.PutCreate(request);
                    Assert.AreEqual(200, response.Code);
                }

                //Add FileVersion.data - first version
                request.Path = string.Format("{0}/FileVersion.data", TempFolderPath);
                request.File = new MemoryStream(new byte[] { 1, 2, 3, 4, 5, 6 });
                var responseVersion = StorageApi.PutCreate(request);
                Assert.AreEqual(200, responseVersion.Code);

                //Add FileVersion.data - second version
                request.File    = new MemoryStream(new byte[] { 1, 2, 3, 4, 5, 6, 7 });
                responseVersion = StorageApi.PutCreate(request);
                Assert.AreEqual(200, responseVersion.Code);
            }
            #endregion
        }
Esempio n. 9
0
        public void FilePutCreateTest()
        {
            string           path    = Path.Combine(dataFolder, "folder2/TestFile1.pdf");
            PutCreateRequest request = new PutCreateRequest();

            request.path      = Path.Combine(dataFolder, "folder4/TestFile1.pdf");
            request.File      = FileApi.GetDownload(new GetDownloadRequest(path, null, storageName));
            request.storage   = destStorageName;
            request.versionId = null;
            var response = FileApi.PutCreate(request);

            Assert.AreEqual(200, response.Code);
        }
 /// <summary>
 /// Uploads file to storage.
 /// </summary>
 /// <param name="path">Path in storage.</param>
 /// <param name="fileContent">File content.</param>
 /// <param name="versionId">Api version.</param>
 /// <param name="storage">Storage.</param>
 protected void UploadFileToStorage(string path, byte[] fileContent, string versionId = null, string storage = null)
 {
     using (var ms = new MemoryStream(fileContent))
     {
         this.StorageApi.GetListFiles(new GetListFilesRequest());
         var request  = new PutCreateRequest(path, ms, versionId, storage);
         var response = this.StorageApi.PutCreate(request);
         if (response?.Code != 200)
         {
             throw new Exception("Can't upload file to the storage. Details: " + response.ToString());
         }
     }
 }
Esempio n. 11
0
        public static FileUploadResult UploadFile(System.Web.HttpPostedFileBase postedFile)
        {
            FileUploadResult uploadResult = null;
            string           fn           = "";

            StorageApi storageApi = new StorageApi(Config.Configuration.AppKey, Config.Configuration.AppSID);

            try
            {
                string folderName = Guid.NewGuid().ToString();

                // Prepare a path in which the result file will be
                string uploadPath = Config.Configuration.WorkingDirectory + "\\" + folderName;

                // Check directroy already exist or not
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }

                // Check if File is available.
                if (postedFile != null && postedFile.ContentLength > 0)
                {
                    fn = System.IO.Path.GetFileName(postedFile.FileName);

                    postedFile.SaveAs(uploadPath + "\\" + fn);
                }

                PutCreateRequest request = new PutCreateRequest(fn, File.OpenRead(uploadPath + "\\" + fn), null, null);

                // Upload original document to Cloud Storage
                storageApi.PutCreate(request);


                // Create response
                return(new FileUploadResult
                {
                    FileName = fn,
                    FolderId = ""
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(uploadResult);
        }
Esempio n. 12
0
        public UploadResponse UploadPdf(string pdfPath, string name)
        {
            if (FileDoesNotExist(pdfPath))
            {
                var response = new UploadResponse();
                response.Code = 404;
                return(response);
            }
            StorageApi storageApi = new StorageApi(_apiKey, _appSid);

            using (var stream = new FileStream(pdfPath, FileMode.Open))
            {
                var request  = new PutCreateRequest(name, stream);
                var response = storageApi.PutCreate(request);
                return(response);
            }
        }
        public void AddFileToCloudStorage_GivenAnExistingPdfFile_ShouldUploadTheFileToCloudStorage()
        {
            var apiKey = "f544165e1e73730ef3216cfa484e682e";
            var appSid = "68a6e9bf-cab2-43d6-82cd-39c351a018b3";

            var baseDirectory = TestContext.CurrentContext.TestDirectory;
            var pdfPath       = Path.Combine(baseDirectory, _fileName);

            using (var stream = new FileStream(pdfPath, FileMode.Open))
            {
                var storageApi = new StorageApi(apiKey, appSid);
                var request    = new PutCreateRequest(_fileName, stream);
                var actual     = storageApi.PutCreate(request);

                Assert.AreEqual(200, actual.Code);
            }
        }
        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));
        }
        public void Test_RecognizeAndImport_Get_1()
        {
            var    name        = "ocr_test_2.png";
            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 respEx   = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(respEx.FileExist.IsExist.HasValue && respEx.FileExist.IsExist.Value);
            }
            var result = OcrApi.GetRecognizeAndImportToHtml(name, "en", folder);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)result).Name));
        }
Esempio n. 16
0
        public void UpdateDataFile(string folder, string filename)
        {
            StorageApi        storageApi = new StorageApi(clientSecret, clientId);
            DeleteFileRequest file       = new DeleteFileRequest();
            PutCreateRequest  newfile    = new PutCreateRequest();

            if (string.IsNullOrEmpty(folder))
            {
                file.Path    = filename;
                newfile.Path = filename;
                newfile.File = File.Open("example_data/" + filename, FileMode.Open);
            }
            else
            {
                file.Path    = folder + "/" + filename;
                newfile.Path = folder + "/" + filename;
                newfile.File = File.Open("example_data/" + filename, FileMode.Open);
            }
            storageApi.DeleteFile(file);
            storageApi.PutCreate(newfile);
            newfile.File.Close();
        }
        public void Test_GetHtmlDetectKeywords_1()
        {
            string name        = "testpage1.html";
            string folder      = "HtmlTestTranslate";
            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);
                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 stream = SummarizationApi.GetDetectHtmlKeywords(name, folder, null);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
        public void Test_GetHtmlConvert_Jpeg_StorageToStream()
        {
            string name   = "testpage1.html";
            string folder = "TempHtml";

            string srcPath = Path.Combine(dataFolder, name);
            string path    = string.Format("{0}/{1}", folder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest reqCr = new PutCreateRequest(path, fstr);
                this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(path);
                FileExistResponse resp     = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value);
            }

            var response = this.ConversionApi.GetConvertDocumentToImage(name, "jpeg", 800, 1200, null, null, null, null, null, null, folder);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)response).Name));
        }
        public void Test_GetDocumentImages()
        {
            string name        = "testpage5.html.zip";
            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);
                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);
            }

            Stream stream = DocumentApi.GetDocumentImages(name, null, folder);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
Esempio n. 20
0
        public UploadResultsTransferObject UploadToAsposeCloud(string path)
        {
            var results = new UploadResultsTransferObject();

            if (Invalid(path))
            {
                results.ErrorMessage = "Invalid file path";
                return(results);
            }
            var name = GetFileName(path);

            if (FileDoesNotExists(path))
            {
                results.ErrorMessage = "File path you looking for does not exist, check path name and try again";
                return(results);
            }

            using (var stream = new FileStream(path, FileMode.Open))
            {
                var request = new PutCreateRequest(name, stream);
                results.UploadResults = _storageApi.PutCreate(request);
            }
            return(results);
        }
        public void Test_GetDocumentFragmentByXPath_2()
        {
            string name        = "testpage1.html";
            string xpath       = ".//ol/li";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";

            string srcPath = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                var reqCr     = new PutCreateRequest(storagePath, fstr);
                var respCr    = this.StorageApi.PutCreate(reqCr);
                var reqExist  = new GetIsExistRequest(storagePath);
                var respExist = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(respExist.FileExist.IsExist.HasValue && respExist.FileExist.IsExist.Value);
            }

            Stream stream = DocumentApi.GetDocumentFragmentByXPath(name, xpath, "json", null, folder);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }