Skip to content

Commit

Permalink
Support uploading of pdf files only
Browse files Browse the repository at this point in the history
  • Loading branch information
savy committed Jul 14, 2021
1 parent 667656d commit c404ab7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 deletions openapi-configuration/jersey2/libraries/jersey2/ApiClient.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,16 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
for (Entry<String, Object> param: formParams.entrySet()) {
if (param.getValue() instanceof File) {
File file = (File) param.getValue();
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
.fileName(file.getName()).size(file.length()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
String filename = file.getName();
if(filename.contains(".") && filename.substring(filename.lastIndexOf(".") + 1).equals("pdf")) {
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
.fileName(file.getName()).size(file.length()).build();
final MediaType APPLICATION_PDF = new MediaType("application", "pdf");
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, APPLICATION_PDF));
}
else {
throw new ApiException("file type check for " + filename + " failed. uploading is only supported for pdf file types");
}
} else {
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down Expand Up @@ -908,7 +915,10 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
public String serializeToString(Object obj, Map<String, Object> formParams, String contentType, boolean isBodyNullable) throws ApiException {
try {
if (contentType.startsWith("multipart/form-data")) {
throw new ApiException("multipart/form-data not yet supported for serializeToString (http signature authentication)");
// todo: find a better solution to allow for serializing large binary data to support http signature authorization
// this workaround should suffice because the Telnyx api doesn't support http signature authorization,
// so this serialized value doesn't get used
return json.getMapper().writeValueAsString(formParams);
} else if (contentType.startsWith("application/x-www-form-urlencoded")) {
String formString = "";
for (Entry<String, Object> param : formParams.entrySet()) {
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/telnyx/sdk/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,16 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
for (Entry<String, Object> param: formParams.entrySet()) {
if (param.getValue() instanceof File) {
File file = (File) param.getValue();
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
.fileName(file.getName()).size(file.length()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
String filename = file.getName();
if(filename.contains(".") && filename.substring(filename.lastIndexOf(".") + 1).equals("pdf")) {
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
.fileName(file.getName()).size(file.length()).build();
final MediaType APPLICATION_PDF = new MediaType("application", "pdf");
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, APPLICATION_PDF));
}
else {
throw new ApiException("file type check for " + filename + " failed. uploading is only supported for pdf file types");
}
} else {
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down Expand Up @@ -720,7 +727,10 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
public String serializeToString(Object obj, Map<String, Object> formParams, String contentType, boolean isBodyNullable) throws ApiException {
try {
if (contentType.startsWith("multipart/form-data")) {
throw new ApiException("multipart/form-data not yet supported for serializeToString (http signature authentication)");
// todo: find a better solution to allow for serializing large binary data to support http signature authorization
// this workaround should suffice because the Telnyx api doesn't support http signature authorization,
// so this serialized value doesn't get used
return json.getMapper().writeValueAsString(formParams);
} else if (contentType.startsWith("application/x-www-form-urlencoded")) {
String formString = "";
for (Entry<String, Object> param : formParams.entrySet()) {
Expand Down

0 comments on commit c404ab7

Please sign in to comment.