public void TestSetUp() { if (!StorageApi.FileOrFolderExists(testoutStorageFolder)) { StorageApi.CreateFolder(testoutStorageFolder); } foreach (var file in templates) { if (!string.IsNullOrEmpty(file)) { var storagePath = Path.Combine(StorageTestDataPath, file).Replace('\\', '/'); if (!StorageApi.FileOrFolderExists(storagePath)) { var localPath = Path.Combine(dataFolder, file); StorageApi.UploadFile(localPath, storagePath); } } } foreach (var file in dataFiles) { if (!string.IsNullOrEmpty(file)) { var storagePath = Path.Combine(StorageTestDataPath, file).Replace('\\', '/'); if (!StorageApi.FileOrFolderExists(storagePath)) { var localPath = Path.Combine(dataFolder, file); StorageApi.UploadFile(localPath, storagePath); } } } }
public void TestSetup() { string path = Path.Combine(StorageTestDataPath, "testpage1.html").Replace('\\', '/'); if (StorageApi.FileOrFolderExists(path)) { string localPath = Path.Combine(LocalTestDataPath, "testpage1.html"); StorageApi.UploadFile(localPath, path); } }
public void Test_PutHtmlConvert_Xps_StorageDocToStorage() { string name = "testpage1.html"; string folder = StorageTestDataPath; string outPath = Path.Combine(testoutStorageFolder, $"{name}_converted_at_{DateTime.Now.ToString("yyMMdd_hhmmss")}.xps"); var response = this.HtmlApi.PutConvertDocumentToXps(name, outPath, null, null, null, null, null, null, folder); Assert.IsNotNull(response); Assert.AreEqual(200, response.Code); Assert.IsTrue(StorageApi.FileOrFolderExists(outPath)); }
public void Run() { // setup storage folder string folder = "/Html/TestData"; // setup storage name; null for default storage string storage = null; IStorageApi stApi = new StorageApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); bool res = stApi.FileOrFolderExists(folder, storage); Console.Out.WriteLine($"Folder: {folder}; exists: {res}"); }
public void Test_PostHtmlConvert_Pdf_LocalFileToStorage() { string name = "testpage1.html"; string outPath = Path.Combine(testoutStorageFolder, $"{name}_converted_at_{DateTime.Now.ToString("yyMMdd_hhmmss")}.pdf"); string srcPath = Path.Combine(LocalTestDataPath, name); using (Stream stream = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) { var response = this.HtmlApi.PostConvertDocumentToPdf(stream, outPath); Assert.IsNotNull(response); Assert.AreEqual(200, response.Code); } Assert.IsTrue(StorageApi.FileOrFolderExists(outPath)); }
protected void uploadFileToStorage(string dataFolder, string name, string folder) { string srcPath = Path.Combine(dataFolder, name); string path = Path.Combine(folder, name).Replace('\\', '/'); using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) { var response = StorageApi.UploadFile(fstr, path); Assert.IsTrue(response != null); Assert.IsTrue(response.Code == 200); bool exists = StorageApi.FileOrFolderExists(path); Assert.IsTrue(exists); } }
public void Test_PutHtmlConvert_Markdown_StorageToStorage() { string name = "testpage1.html"; string folder = StorageTestDataPath; string storage = null; string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted_at_{DateTime.Now.ToString("yyyyMMdd-hhmmss")}.md"; string outPath = Path.Combine(testoutStorageFolder, outFile).Replace('\\', '/'); var response = this.HtmlApi.PutConvertDocumentToMarkdown(name, outPath, false, folder, storage); Assert.IsNotNull(response); Assert.AreEqual(200, response.Code); Assert.IsTrue(StorageApi.FileOrFolderExists(outPath)); }
/// <summary> /// Aspose.HTML Cloud for .NET SDK - examples. /// ========================================= /// Example that demonstrates how to check if a file exists in the storage /// by specified name and folder path. /// </summary> public void Run() { // setup name of a storage file string name = "testpage7-ru.html"; // setup a folder path where the file is located string folder = "/Html/TestData"; // setup storage name (null for default storage) string storage = null; var filePath = Path.Combine(folder, name).Replace('\\', '/'); IStorageApi stApi = new StorageApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); bool res = stApi.FileOrFolderExists(filePath, storage); Console.Out.WriteLine($"File: {filePath}; exists: {res}"); }
public void TestSetUp() { string[] files = new string[] { "testpage1.html", "testpage5.html.zip" }; foreach (string fname in files) { var storagePath = Path.Combine(StorageTestDataPath, fname).Replace('\\', '/'); if (!StorageApi.FileOrFolderExists(storagePath)) { var localPath = Path.Combine(dataFolder, fname); StorageApi.UploadFile(localPath, storagePath); } } }
public void Run() { // setup name of a storage file string name = "testpage7-ru.html"; // setup a folder path where the file is located string folder = "/Html/TestData"; // setup storage name (null for default storage) string storage = null; var filePath = Path.Combine(folder, name).Replace('\\', '/'); IStorageApi stApi = new StorageApi(); // default constructor; appSid, appKey, basePath, authPath aren't specified explicitly // but obtained from config file or environment variables bool res = stApi.FileOrFolderExists(filePath, storage); Console.Out.WriteLine($"File: {filePath}; exists: {res}"); }
public static bool UploadToStorage(string storagePath, string srcPath = null, string storage = null) { var name = Path.GetFileName(storagePath); Configuration storageConf = new Configuration() { ApiBaseUrl = CommonSettings.BasePath, ClientId = CommonSettings.ClientId, ClientSecret = CommonSettings.ClientSecret, AuthUrl = CommonSettings.AuthPath, ApiVersion = "3.0" }; StorageApi storageApi = new StorageApi(storageConf); // Upload source file to aspose cloud storage if (File.Exists(srcPath)) { var storageFolder = Path.GetDirectoryName(storagePath).Replace('\\', '/'); // check if storagePath folder exists and create it if not if (!storageApi.FileOrFolderExists(storageFolder, storage)) { var resp = storageApi.CreateFolder(storageFolder, storage); if (resp.Code == 200) { Console.Out.WriteLine($"Folder {storageFolder} successfully created."); } } using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) { var response = storageApi.UploadFile(fstr, storagePath, storage); if (response.Code == 200) { Console.Out.WriteLine($"File {name} successfully uploaded with path {storagePath} ."); } return(true); } } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } }
public void Run() { string name = "testpage4_embcss.html"; string path = Path.Combine(CommonSettings.LocalDataFolder, name); if (!File.Exists(path)) { throw new FileNotFoundException("File not found in the Data folder", name); } string folder = "/Html/Testout/Conversion"; string storage = null; int width = 800; int height = 1200; int leftMargin = 15; int rightMargin = 15; int topMargin = 15; int bottomMargin = 15; int resolution = 96; string ext = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted_at_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.{ext}"; string outPath = Path.Combine(folder, outFile).Replace('\\', '/'); using (Stream srcStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { IConversionApi convApi = new HtmlApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); IStorageApi storageApi = new StorageApi((ApiBase)convApi); if (!storageApi.FileOrFolderExists(folder, storage)) { ((IStorageFolderApi)storageApi).CreateFolder(folder, storage); } AsposeResponse response = null; string dataType = Path.GetExtension(name).Replace(".", ""); // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": outFile += ".pdf"; response = convApi.PostConvertDocumentToPdf( srcStream, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "xps": response = convApi.PostConvertDocumentToXps( srcStream, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "jpeg": case "bmp": case "png": case "tiff": case "gif": response = convApi.PostConvertDocumentToImage( srcStream, Format, outPath, width, height, leftMargin, rightMargin, topMargin, bottomMargin, resolution, storage); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && response.Status == "OK") { storageApi = new StorageApi((ApiBase)convApi); if (storageApi.FileOrFolderExists(outPath)) { Console.WriteLine(string.Format("\nResult file uploaded to: {0}", outPath)); } } } }