forked from loafle/openapi-generator-original
[Bugfix][Java] Fixed jersey clients for multiple file upload (#19476)
* Fixed jersey3 client for multiple file upload * Updated sample * Fixed typo * Fix * Fix for jersey2
This commit is contained in:
parent
c733bb69a2
commit
fb1c2f3483
@ -988,24 +988,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -1034,6 +1020,36 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -988,24 +988,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -1034,6 +1020,36 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -767,24 +767,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -813,6 +799,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -767,24 +767,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -813,6 +799,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -908,24 +908,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -954,6 +940,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -908,24 +908,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -954,6 +940,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -990,24 +990,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -1036,6 +1022,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -816,24 +816,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -862,6 +848,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -767,24 +767,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -813,6 +799,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -892,24 +892,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -938,6 +924,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -892,24 +892,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -938,6 +924,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
@ -990,24 +990,10 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
if (param.getValue() instanceof File) {
|
if (param.getValue() instanceof Iterable) {
|
||||||
File file = (File) param.getValue();
|
((Iterable)param.getValue()).forEach(v -> addParamToMultipart(v, param.getKey(), multiPart));
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
|
|
||||||
.fileName(file.getName()).size(file.length()).build();
|
|
||||||
|
|
||||||
// Attempt to probe the content type for the file so that the form part is more correctly
|
|
||||||
// and precisely identified, but fall back to application/octet-stream if that fails.
|
|
||||||
MediaType type;
|
|
||||||
try {
|
|
||||||
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
|
||||||
} catch (IOException | IllegalArgumentException e) {
|
|
||||||
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
|
||||||
} else {
|
} else {
|
||||||
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
|
addParamToMultipart(param.getValue(), param.getKey(), multiPart);
|
||||||
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
entity = Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||||
@ -1036,6 +1022,36 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the object with the provided key to the MultiPart.
|
||||||
|
* Based on the object type sets Content-Disposition and Content-Type.
|
||||||
|
*
|
||||||
|
* @param obj Object
|
||||||
|
* @param key Key of the object
|
||||||
|
* @param multiPart MultiPart to add the form param to
|
||||||
|
*/
|
||||||
|
private void addParamToMultipart(Object value, String key, MultiPart multiPart) {
|
||||||
|
if (value instanceof File) {
|
||||||
|
File file = (File) value;
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key)
|
||||||
|
.fileName(file.getName()).size(file.length()).build();
|
||||||
|
|
||||||
|
// Attempt to probe the content type for the file so that the form part is more correctly
|
||||||
|
// and precisely identified, but fall back to application/octet-stream if that fails.
|
||||||
|
MediaType type;
|
||||||
|
try {
|
||||||
|
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
|
||||||
|
} catch (IOException | IllegalArgumentException e) {
|
||||||
|
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
|
||||||
|
} else {
|
||||||
|
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(key).build();
|
||||||
|
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize the given Java object into string according the given
|
* Serialize the given Java object into string according the given
|
||||||
* Content-Type (only JSON, HTTP form is supported for now).
|
* Content-Type (only JSON, HTTP form is supported for now).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user