public void TestSetup() { if (!StorageApi.FileOrFolderExists(testoutStorageFolder)) { StorageApi.CreateFolder(testoutStorageFolder); } 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 Run() { string folder = CommonSettings.StorageDataFolder; // setup folder path to create string newFolder = Path.Combine(folder, "NewFolder").Replace('\\', '/');; // setup storage name (your default storage if null) string storage = null; IStorageFolderApi api = new StorageApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath); var response = api.CreateFolder(newFolder, storage); if (response.Code == 200) { IStorageApi stApi = (IStorageApi)api; stApi.FileOrFolderExists(newFolder, storage); Console.Write($"Folder {newFolder} successfully created"); } }
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 static void UploadSampleTestFiles() { var storageConfig = new Configuration { AppSid = MyAppSid, AppKey = MyAppKey, }; StorageApi storageApi = new StorageApi(storageConfig); var path = "..\\..\\Resources"; var dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories); foreach (var dir in dirs) { var relativeDirPath = dir.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); var response = storageApi.IsExist(relativeDirPath); if (!response.FileExist.IsExist) { storageApi.CreateFolder(relativeDirPath); } } var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); foreach (var file in files) { var relativeFilePath = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); var response = storageApi.IsExist(relativeFilePath); if (!response.FileExist.IsExist) { var fileName = Path.GetFileName(file); var relativeDirPath = relativeFilePath.Replace(fileName, string.Empty).Trim(Path.DirectorySeparatorChar); var bytes = File.ReadAllBytes(file); storageApi.CreateFile(fileName, relativeDirPath, bytes); } } }