-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upload + raw JSON DotNet samples
- Loading branch information
1 parent
026ca08
commit 379378e
Showing
34 changed files
with
1,736 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This directory contains examples of how to call each endpoint of the | ||
PdfRest API using DotNet. Please refer to https://pdfrest.com/documentation.html | ||
for accepted inputs, options, and other specifics about individual endpoints. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var uploadRequest = new HttpRequestMessage(HttpMethod.Post, "upload")) | ||
{ | ||
uploadRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
uploadRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
var uploadByteArray = File.ReadAllBytes("/path/to/file"); | ||
var uploadByteAryContent = new ByteArrayContent(uploadByteArray); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream"); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Filename", "filename.pdf"); | ||
|
||
|
||
uploadRequest.Content = uploadByteAryContent; | ||
var uploadResponse = await httpClient.SendAsync(uploadRequest); | ||
|
||
var uploadResult = await uploadResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Upload response received."); | ||
Console.WriteLine(uploadResult); | ||
|
||
JObject uploadResultJson = JObject.Parse(uploadResult); | ||
var uploadedID = uploadResultJson["files"][0]["id"]; | ||
using (var bmpRequest = new HttpRequestMessage(HttpMethod.Post, "bmp")) | ||
{ | ||
bmpRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
bmpRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
bmpRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json"); | ||
|
||
|
||
JObject parameterJson = new JObject | ||
{ | ||
["id"] = uploadedID, | ||
}; | ||
|
||
bmpRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ; | ||
var bmpResponse = await httpClient.SendAsync(bmpRequest); | ||
|
||
var bmpResult = await bmpResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Processing response received."); | ||
Console.WriteLine(bmpResult); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var uploadRequest = new HttpRequestMessage(HttpMethod.Post, "upload")) | ||
{ | ||
uploadRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
uploadRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
var uploadByteArray = File.ReadAllBytes("/path/to/file"); | ||
var uploadByteAryContent = new ByteArrayContent(uploadByteArray); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream"); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Filename", "filename.pdf"); | ||
|
||
|
||
uploadRequest.Content = uploadByteAryContent; | ||
var uploadResponse = await httpClient.SendAsync(uploadRequest); | ||
|
||
var uploadResult = await uploadResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Upload response received."); | ||
Console.WriteLine(uploadResult); | ||
|
||
JObject uploadResultJson = JObject.Parse(uploadResult); | ||
var uploadedID = uploadResultJson["files"][0]["id"]; | ||
using (var compressRequest = new HttpRequestMessage(HttpMethod.Post, "compressed-pdf")) | ||
{ | ||
compressRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
compressRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
compressRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json"); | ||
|
||
|
||
JObject parameterJson = new JObject | ||
{ | ||
["id"] = uploadedID, | ||
["compression_level"] = "medium" | ||
}; | ||
|
||
compressRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ; | ||
var compressResponse = await httpClient.SendAsync(compressRequest); | ||
|
||
var compressResult = await compressResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Processing response received."); | ||
Console.WriteLine(compressResult); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var uploadRequest = new HttpRequestMessage(HttpMethod.Post, "upload")) | ||
{ | ||
uploadRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
uploadRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
var uploadByteArray = File.ReadAllBytes("/path/to/file"); | ||
var uploadByteAryContent = new ByteArrayContent(uploadByteArray); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream"); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Filename", "filename.pdf"); | ||
|
||
|
||
uploadRequest.Content = uploadByteAryContent; | ||
var uploadResponse = await httpClient.SendAsync(uploadRequest); | ||
|
||
var uploadResult = await uploadResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Upload response received."); | ||
Console.WriteLine(uploadResult); | ||
|
||
JObject uploadResultJson = JObject.Parse(uploadResult); | ||
var uploadedID = uploadResultJson["files"][0]["id"]; | ||
using (var decryptRequest = new HttpRequestMessage(HttpMethod.Post, "decrypted-pdf")) | ||
{ | ||
decryptRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
decryptRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
decryptRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json"); | ||
|
||
|
||
JObject parameterJson = new JObject | ||
{ | ||
["id"] = uploadedID, | ||
["current_open_password"] = "password" | ||
}; | ||
|
||
decryptRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ; | ||
var decryptResponse = await httpClient.SendAsync(decryptRequest); | ||
|
||
var decryptResult = await decryptResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Processing response received."); | ||
Console.WriteLine(decryptResult); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var uploadRequest = new HttpRequestMessage(HttpMethod.Post, "upload")) | ||
{ | ||
uploadRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
uploadRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
var uploadByteArray = File.ReadAllBytes("/path/to/file"); | ||
var uploadByteAryContent = new ByteArrayContent(uploadByteArray); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream"); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Filename", "filename.pdf"); | ||
|
||
|
||
uploadRequest.Content = uploadByteAryContent; | ||
var uploadResponse = await httpClient.SendAsync(uploadRequest); | ||
|
||
var uploadResult = await uploadResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Upload response received."); | ||
Console.WriteLine(uploadResult); | ||
|
||
JObject uploadResultJson = JObject.Parse(uploadResult); | ||
var uploadedID = uploadResultJson["files"][0]["id"]; | ||
using (var encryptRequest = new HttpRequestMessage(HttpMethod.Post, "encrypted-pdf")) | ||
{ | ||
encryptRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
encryptRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
encryptRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json"); | ||
|
||
|
||
JObject parameterJson = new JObject | ||
{ | ||
["id"] = uploadedID, | ||
["new_open_password"] = "password" | ||
}; | ||
|
||
encryptRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ; | ||
var encryptResponse = await httpClient.SendAsync(encryptRequest); | ||
|
||
var encryptResult = await encryptResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Processing response received."); | ||
Console.WriteLine(encryptResult); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var uploadRequest = new HttpRequestMessage(HttpMethod.Post, "upload")) | ||
{ | ||
uploadRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
uploadRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
var uploadByteArray = File.ReadAllBytes("/path/to/file"); | ||
var uploadByteAryContent = new ByteArrayContent(uploadByteArray); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream"); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Filename", "filename.pdf"); | ||
|
||
|
||
uploadRequest.Content = uploadByteAryContent; | ||
var uploadResponse = await httpClient.SendAsync(uploadRequest); | ||
|
||
var uploadResult = await uploadResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Upload response received."); | ||
Console.WriteLine(uploadResult); | ||
|
||
JObject uploadResultJson = JObject.Parse(uploadResult); | ||
var uploadedID = uploadResultJson["files"][0]["id"]; | ||
using (var excelRequest = new HttpRequestMessage(HttpMethod.Post, "excel")) | ||
{ | ||
excelRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
excelRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
excelRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json"); | ||
|
||
|
||
JObject parameterJson = new JObject | ||
{ | ||
["id"] = uploadedID, | ||
}; | ||
|
||
excelRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ; | ||
var excelResponse = await httpClient.SendAsync(excelRequest); | ||
|
||
var excelResult = await excelResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Processing response received."); | ||
Console.WriteLine(excelResult); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
DotNET/Endpoint Examples/JSON Payload/exported-form-data.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var uploadRequest = new HttpRequestMessage(HttpMethod.Post, "upload")) | ||
{ | ||
uploadRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
uploadRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
var uploadByteArray = File.ReadAllBytes("/path/to/file"); | ||
var uploadByteAryContent = new ByteArrayContent(uploadByteArray); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream"); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Filename", "filename.pdf"); | ||
|
||
|
||
uploadRequest.Content = uploadByteAryContent; | ||
var uploadResponse = await httpClient.SendAsync(uploadRequest); | ||
|
||
var uploadResult = await uploadResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Upload response received."); | ||
Console.WriteLine(uploadResult); | ||
|
||
JObject uploadResultJson = JObject.Parse(uploadResult); | ||
var uploadedID = uploadResultJson["files"][0]["id"]; | ||
using (var exportRequest = new HttpRequestMessage(HttpMethod.Post, "exported-form-data")) | ||
{ | ||
exportRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
exportRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
exportRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json"); | ||
|
||
|
||
JObject parameterJson = new JObject | ||
{ | ||
["id"] = uploadedID, | ||
["data_format"] = "xml", | ||
}; | ||
|
||
exportRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ; | ||
var exportResponse = await httpClient.SendAsync(exportRequest); | ||
|
||
var exportResult = await exportResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Processing response received."); | ||
Console.WriteLine(exportResult); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
using Newtonsoft.Json.Linq; | ||
using System.Text; | ||
|
||
using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) | ||
{ | ||
using (var uploadRequest = new HttpRequestMessage(HttpMethod.Post, "upload")) | ||
{ | ||
uploadRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
uploadRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
var uploadByteArray = File.ReadAllBytes("/path/to/file"); | ||
var uploadByteAryContent = new ByteArrayContent(uploadByteArray); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/octet-stream"); | ||
uploadByteAryContent.Headers.TryAddWithoutValidation("Content-Filename", "filename.pdf"); | ||
|
||
|
||
uploadRequest.Content = uploadByteAryContent; | ||
var uploadResponse = await httpClient.SendAsync(uploadRequest); | ||
|
||
var uploadResult = await uploadResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Upload response received."); | ||
Console.WriteLine(uploadResult); | ||
|
||
JObject uploadResultJson = JObject.Parse(uploadResult); | ||
var uploadedID = uploadResultJson["files"][0]["id"]; | ||
using (var extractRequest = new HttpRequestMessage(HttpMethod.Post, "extracted-text")) | ||
{ | ||
extractRequest.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); | ||
extractRequest.Headers.Accept.Add(new("application/json")); | ||
|
||
extractRequest.Headers.TryAddWithoutValidation("Content-Type", "application/json"); | ||
|
||
|
||
JObject parameterJson = new JObject | ||
{ | ||
["id"] = uploadedID, | ||
}; | ||
|
||
extractRequest.Content = new StringContent(parameterJson.ToString(), Encoding.UTF8, "application/json"); ; | ||
var extractResponse = await httpClient.SendAsync(extractRequest); | ||
|
||
var extractResult = await extractResponse.Content.ReadAsStringAsync(); | ||
|
||
Console.WriteLine("Processing response received."); | ||
Console.WriteLine(extractResult); | ||
} | ||
} | ||
} |
Oops, something went wrong.