Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][Jersey2/3] Probe content type for multipart upload parts #14965

Merged
merged 6 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,15 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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));

wing328 marked this conversation as resolved.
Show resolved Hide resolved
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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,15 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,15 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,15 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,15 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,15 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,15 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,15 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,15 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
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));

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(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down