public static void Run() { // ExStart:1 PdfApi pdfApi = new PdfApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); String fileName = "Lenovo_Tablet_2_Datasheet.pdf"; String format = "html"; String storage = ""; String folder = ""; String outPath = "Lenovo_Tablet_2_Datasheet.zip"; try { // Upload source file to aspose cloud storage storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName)); // Invoke Aspose.PDF Cloud SDK API to convert pdf to HTML ResponseMessage apiResponse = pdfApi.GetDocumentWithFormat(fileName, format, storage, folder, outPath); if (apiResponse != null) { // Download converted HTML file Com.Aspose.Storage.Model.ResponseMessage storageRes = storageApi.GetDownload(outPath, null, storage); // Save response stream to a file System.IO.File.WriteAllBytes(Common.GetDataDir() + outPath, storageRes.ResponseStream); Console.WriteLine("Convert PDF to HTML, Done!"); Console.ReadKey(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
public static void Run() { // ExStart:1 SlidesApi slidesApi = new SlidesApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); String fileName = "sample-input.pptx"; String oldValue = "aspose"; String newValue = "aspose2"; bool ignoreCase = true; String folder = ""; String storage = ""; try { // Upload source file to aspose cloud storage storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName)); // Invoke Aspose.Slides Cloud SDK API to get all text instances from presentation PresentationStringReplaceResponse apiResponse = slidesApi.PostSlidesPresentationReplaceText(fileName, oldValue, newValue, ignoreCase, folder, storage); if (apiResponse != null && apiResponse.Status.Equals("OK")) { // Download updated presentation from cloud storage Com.Aspose.Storage.Model.ResponseMessage storageRes = storageApi.GetDownload(fileName, null, null); System.Diagnostics.Debug.WriteLine("response:" + storageRes.ResponseStream); System.IO.File.WriteAllBytes(Common.GetDataDir() + fileName, storageRes.ResponseStream); Console.WriteLine("Replace All Text Instances in a Presentation, Done!"); Console.ReadKey(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
public void Run() { string srcUrl = @"http://www.htmlhelp.com/reference/css/stylesheets-now.html"; //string srcUrl = @"https://www.le.ac.uk/oerresources/bdra/html/page_01.htm"; string folder = null; // default folder is root string storage = null; // default storage is AmazonS3 TranslationApi transApi = new TranslationApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); NativeRestResponse resp = transApi.PutTranslateDocumentByUrl(srcUrl, SrcLang, ResLang, folder, storage); if (resp.ContentType == NativeRestResponse.RespContentType.FileName && resp.ContentName != null) { StorageApi storageApi = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); var storagePath = !string.IsNullOrEmpty(folder) ? string.Format("{0}/{1}", folder, resp.ContentName) : resp.ContentName; var stResp = storageApi.GetIsExist(storagePath, null, storage); if (stResp.FileExist.IsExist) { Console.WriteLine(string.Format("\nFile '{0}' created in the cloud storage: folder = '{1}', storage = '{2}' ", resp.ContentName, folder ?? "", storage ?? "<default>")); ResponseMessage resp2 = storageApi.GetDownload(storagePath, null, storage); using (MemoryStream resStream = new MemoryStream(resp2.ResponseStream)) { var outPath = Path.Combine(CommonSettings.OutDirectory, resp.ContentName); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { resStream.Position = 0; resStream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } } } }
public DownloadResultsTransferObject DownloadDocumentFromTheCloud(string name, string path) { var results = new DownloadResultsTransferObject(); if (Invalid(name)) { results.ErrorMessage = "Invalid file name"; return(results); } var request = new GetDownloadRequest(name); using (var response = _storageApi.GetDownload(request)) { if (response == null) { results.ErrorMessage = "File you looking for does not exist, check filename and try again"; return(results); } results.Bytes = response.ReadAsBytes(); File.WriteAllBytes(path, results.Bytes); } return(results); }
public static void Run() { // ExStart:1 StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); string Path = "Book1.xlsx"; string versionId = null; string storage = null; byte[] file = System.IO.File.ReadAllBytes(Common.GetDataDir() + Path); try { // Invoke Aspose.Storage Cloud SDK API to upload and download file storageApi.PutCreate(Path, versionId, storage, file); Com.Aspose.Storage.Model.ResponseMessage storageRes = storageApi.GetDownload(Path, versionId, storage); System.Diagnostics.Debug.WriteLine("response:" + storageRes.ResponseStream); System.IO.File.WriteAllBytes(Common.GetDataDir() + Path, storageRes.ResponseStream); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
public static void Run() { // ExStart:1 EmailApi emailApi = new EmailApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); String name = "email_test"; String fileName = name + ".eml"; String storage = ""; String folder = ""; EmailDocument body = new EmailDocument(); EmailProperties emailProperties = new EmailProperties(); System.Collections.Generic.List <Link> links = new System.Collections.Generic.List <Link> { }; System.Collections.Generic.List <EmailProperty> empProps = new System.Collections.Generic.List <EmailProperty> { }; Link link = new Link(); link.Href = "http://api.aspose.com/v1.1/pdf/"; link.Rel = "self"; link.Title = "NewField"; link.Type = "link"; links.Add(link); EmailProperty emailBody = new EmailProperty(); EmailProperty emailTo = new EmailProperty(); EmailProperty emailFrom = new EmailProperty(); emailBody.Name = "Body"; emailBody.Value = "This is the Body"; emailBody.Link = link; empProps.Add(emailBody); emailTo.Name = "To"; emailTo.Value = "*****@*****.**"; emailTo.Link = link; empProps.Add(emailTo); emailFrom.Name = "From"; emailFrom.Value = "*****@*****.**"; emailFrom.Link = link; empProps.Add(emailFrom); emailProperties.List = empProps; emailProperties.Link = link; body.DocumentProperties = emailProperties; body.Links = links; try { // Invoke Aspose.Email Cloud SDK API to add new email EmailDocumentResponse apiResponse = emailApi.PutCreateNewEmail(fileName, storage, folder, body); if (apiResponse != null) { Com.Aspose.Storage.Model.ResponseMessage storageRes = storageApi.GetDownload(fileName, null, null); System.IO.File.WriteAllBytes(Common.GetDataDir() + fileName, storageRes.ResponseStream); Console.WriteLine("Add New Email, Done!"); Console.ReadKey(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
/// <summary> /// Sends back specified file from specified folder inside OutputDirectory. /// </summary> /// <param name="folder">Folder inside OutputDirectory.</param> /// <param name="file">File.</param> /// <returns>HTTP response with file.</returns> public FileResult DownloadFile(string file) { GetDownloadRequest getDownloadRequest = new GetDownloadRequest(file); return(File(storageApi.GetDownload(getDownloadRequest), "application/octet-stream", file)); }
public void Run() { string name = "testpage4_embcss.html"; string path = Path.Combine(CommonSettings.DataFolder, name); if (!File.Exists(path)) { throw new FileNotFoundException("File not found in the Data folder", name); } string folder = null; string storage = null; int width = 800; int height = 1200; int leftMargin = 15; int rightMargin = 15; int topMargin = 15; int bottomMargin = 15; int xResolution = 96; int yResolution = 96; string ext = (Format == "tiff") ? "tif" : ((Format == "jpeg") ? "jpg" : Format); string outFile = $"{Path.GetFileNameWithoutExtension(name)}_converted.{ext}"; using (Stream srcStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { IConversionApi convApi = new ConversionApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); NativeRestResponse response = null; // call SDK methods that convert HTML document to supported out format switch (Format) { case "pdf": outFile += ".pdf"; response = convApi.PutConvertDocumentToPdf( srcStream, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "xps": response = convApi.PutConvertDocumentToXps( srcStream, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, storage); break; case "jpeg": case "bmp": case "png": case "tiff": response = convApi.PutConvertDocumentToImage( srcStream, Format, outFile, width, height, leftMargin, rightMargin, topMargin, bottomMargin, xResolution, yResolution, storage); break; default: throw new ArgumentException($"Unsupported output format: {Format}"); } if (response != null && (string)response.Content == "storage" && response.ContentType == NativeRestResponse.RespContentType.FileName) { // get the result file name from response object string outFileName = response.ContentName; StorageApi storageApi = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); FileExistResponse resp2 = storageApi.GetIsExist(outFileName, null, null); if (resp2.FileExist.IsExist) { // if result file exists in the storage, try to downloa it to the local file system var resp3 = storageApi.GetDownload(outFileName, null, null); if (resp3.ResponseStream != null) { string outPath = Path.Combine(CommonSettings.OutDirectory, outFileName); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { fstr.Write(resp3.ResponseStream, 0, resp3.ResponseStream.Length); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } } else { Console.WriteLine("Error: result file wasn't saved to storage."); } } } }