Added support for PDFs and Images

This commit is contained in:
2023-12-23 17:19:12 -05:00
parent 16a1c9a06f
commit 03e69393fc
8 changed files with 161 additions and 66 deletions

View File

@@ -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':''}\"";
}
}
}
}