|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "path" |
| 7 | + "path/filepath" |
| 8 | + |
| 9 | + asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25" |
| 10 | +) |
| 11 | + |
| 12 | +// Set file names and folders |
| 13 | +const ( |
| 14 | + REMOTE_FOLDER = "Merge_Temp_Pdf_Cloud" |
| 15 | + LOCAL_FOLDER = "c:\\Samples" |
| 16 | + PDF_DOCUMENT = "sample.pdf" |
| 17 | + PDF_DOCUMENT_2 = "sample_2.pdf" |
| 18 | + PDF_DOCUMENT_3 = "sample_3.pdf" |
| 19 | + PDF_OUTPUT = "output_sample.pdf" |
| 20 | +) |
| 21 | + |
| 22 | +// Initialize credentials and Rest API service |
| 23 | +func initPdfApi() *asposepdfcloud.PdfApiService { |
| 24 | + AppSID := "*****" |
| 25 | + AppKey := "*****" |
| 26 | + |
| 27 | + pdfApi := asposepdfcloud.NewPdfApiService(AppSID, AppKey, "") |
| 28 | + return pdfApi |
| 29 | +} |
| 30 | + |
| 31 | +// Upload local file to the remote folder with check errors |
| 32 | +func uploadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { |
| 33 | + args := map[string]interface{}{ |
| 34 | + "folder": REMOTE_FOLDER, |
| 35 | + } |
| 36 | + file, err := os.Open(filepath.Join(LOCAL_FOLDER, name)) |
| 37 | + if err != nil { |
| 38 | + fmt.Println(err.Error()) |
| 39 | + } else { |
| 40 | + result, httpResponse, err := pdf_api.UploadFile(path.Join(REMOTE_FOLDER, name), file, args) |
| 41 | + if err != nil { |
| 42 | + fmt.Println(err.Error()) |
| 43 | + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { |
| 44 | + fmt.Println("Unexpected error!") |
| 45 | + } else { |
| 46 | + fmt.Println(result) |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +// Download file from remote folder and save it locally with check errors |
| 52 | +func downloadFile(pdf_api *asposepdfcloud.PdfApiService, name string) { |
| 53 | + args := map[string]interface{}{ |
| 54 | + "folder": REMOTE_FOLDER, |
| 55 | + } |
| 56 | + result_data, httpResponse, err := pdf_api.DownloadFile(path.Join(REMOTE_FOLDER, name), args) |
| 57 | + if err != nil { |
| 58 | + fmt.Println(err.Error()) |
| 59 | + } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 { |
| 60 | + fmt.Println("Unexpected error!") |
| 61 | + } else { |
| 62 | + fmt.Println("File '" + name + "'successfully downloaded.") |
| 63 | + fileName := path.Join(LOCAL_FOLDER, PDF_OUTPUT) |
| 64 | + f, _ := os.Create(fileName) |
| 65 | + _, _ = f.Write(result_data) |
| 66 | + } |
| 67 | +} |
0 commit comments