Added support for PDFs and Images
This commit is contained in:
@@ -27,6 +27,10 @@ namespace PWAPPv2.Source.API
|
||||
Client.BaseAddress = new Uri(BaseURL);
|
||||
Client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
Client.DefaultRequestHeaders.Add("UserID", Credentials.UserID);
|
||||
Client.DefaultRequestHeaders.Add("Password", Credentials.Password);
|
||||
Client.DefaultRequestHeaders.Add("PracticeID", Credentials.PracticeId);
|
||||
Client.DefaultRequestHeaders.Add("ApiID", Credentials.APIid);
|
||||
|
||||
}
|
||||
|
||||
@@ -94,20 +98,17 @@ namespace PWAPPv2.Source.API
|
||||
/// <exception cref="RequestFailedExcpetion"></exception>
|
||||
public string SendPostWithCredsInHeader(string apiUri, string PostData)
|
||||
{
|
||||
Client.DefaultRequestHeaders.Add("UserID", Credentials.UserID);
|
||||
Client.DefaultRequestHeaders.Add("Password", Credentials.Password);
|
||||
Client.DefaultRequestHeaders.Add("PracticeID", Credentials.PracticeId);
|
||||
Client.DefaultRequestHeaders.Add("ApiID", Credentials.APIid);
|
||||
|
||||
|
||||
StringContent content = new StringContent(PostData, Encoding.UTF8, "application/json");
|
||||
string conts = content.ToString();
|
||||
|
||||
var response = Client.PostAsync(apiUri, content).Result;
|
||||
|
||||
Client.DefaultRequestHeaders.Remove("UserID");
|
||||
Client.DefaultRequestHeaders.Remove("Password");
|
||||
Client.DefaultRequestHeaders.Remove("PraticeID");
|
||||
Client.DefaultRequestHeaders.Remove("ApiID");
|
||||
//Client.DefaultRequestHeaders.Remove("UserID");
|
||||
//Client.DefaultRequestHeaders.Remove("Password");
|
||||
//Client.DefaultRequestHeaders.Remove("PraticeID");
|
||||
//Client.DefaultRequestHeaders.Remove("ApiID");
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
|
||||
@@ -3,32 +3,59 @@
|
||||
class Attachment
|
||||
{
|
||||
APICredentials Credentials;
|
||||
PWImage image;
|
||||
public PWImage image { get; set; }
|
||||
public PWPdf pdf { get; set; }
|
||||
public string Token;
|
||||
|
||||
string Token;
|
||||
private string fileType { get; set; }
|
||||
|
||||
|
||||
public Attachment(APICredentials credentials, PWImage pwImage, string token)
|
||||
public Attachment(APICredentials credentials, PWImage pwImage)
|
||||
{
|
||||
Credentials = credentials;
|
||||
image = pwImage;
|
||||
Token = token;
|
||||
//Token = token;
|
||||
pdf = null;
|
||||
fileType = "image/jpeg";
|
||||
}
|
||||
|
||||
public Attachment(APICredentials credentials, PWPdf pwPdf)
|
||||
{
|
||||
Credentials = credentials;
|
||||
pdf = pwPdf;
|
||||
image = null;
|
||||
fileType = "application/pdf";
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return "\"{" + Credentials.BuildJsonBodyContents() +
|
||||
",'UserNum':'API'," +
|
||||
"'AttToken':'" + Token.Replace("\"", "") + "'," +
|
||||
"'FileName':'" + image.ShortFileName() + "'," +
|
||||
"'ContentType':'_1'," +
|
||||
"'ThumbExists':'1'," +
|
||||
"'ZoomExists':'1'," +
|
||||
"'FileDate':''," +
|
||||
"'Base64FileContents':'" + image.GetBase64String() + "',\n" +
|
||||
"'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" +
|
||||
"'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\"";
|
||||
if (fileType == "image/jpeg")
|
||||
{
|
||||
return "\"{" + Credentials.BuildJsonBodyContents() +
|
||||
",'UserNum':'API'," +
|
||||
"'AttToken':'" + Token.Replace("\"", "") + "'," +
|
||||
"'FileName':'" + image.ShortFileName() + "'," +
|
||||
"'ThumbExists':'1'," +
|
||||
"'ZoomExists':'1'," +
|
||||
"'FileDate':''," +
|
||||
"'FileType':'" + fileType + "'," +
|
||||
"'Base64FileContents':'" + image.GetBase64String() + "',\n" +
|
||||
"'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" +
|
||||
"'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "\"{" + Credentials.BuildJsonBodyContents() +
|
||||
",'UserNum':'API'," +
|
||||
"'AttToken':'" + Token.Replace("\"", "") + "'," +
|
||||
"'FileName':'" + pdf.ShortFileName() + "'," +
|
||||
"'ThumbExists':'0'," +
|
||||
"'ZoomExists':'0'," +
|
||||
"'FileDate':''," +
|
||||
"'FileType':'" + fileType + "'," +
|
||||
"'Base64FileContents':'" + pdf.GetBase64String() + "',\n" +
|
||||
"'Base64ThumbContents':'',\n" +
|
||||
"'Base64ZoomContents':''}\"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
31
PWAPPv2/Source/DataObjects/PWPdf.cs
Normal file
31
PWAPPv2/Source/DataObjects/PWPdf.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAPPv2.Source.DataObjects
|
||||
{
|
||||
public class PWPdf
|
||||
{
|
||||
public string path;
|
||||
|
||||
|
||||
public PWPdf(string path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public string GetBase64String()
|
||||
{
|
||||
byte[] bytes = File.ReadAllBytes(path);
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
|
||||
public string ShortFileName()
|
||||
{
|
||||
return path.Substring(path.LastIndexOf("\\") + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user