We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
PartMap should add filename to each file part, because many Java servlet container treat part as an upload file only by the filename attribute.
Also, the Content-Transfer-Encoding header is useless.
I hacked the PartMap impl
static final class PartMap extends RequestBuilderAction { private final Retrofit retrofit; private final String transferEncoding; private final Annotation[] annotations; PartMap(Retrofit retrofit, String transferEncoding, Annotation[] annotations) { this.retrofit = retrofit; this.transferEncoding = transferEncoding; this.annotations = annotations; } @Override void perform(RequestBuilder builder, Object value) { if (value == null) return; // Skip null values. Map<?, ?> map = (Map<?, ?>) value; for (Map.Entry<?, ?> entry : map.entrySet()) { Object entryKey = entry.getKey(); if (entryKey == null) { throw new IllegalArgumentException("Part map contained null key."); } Object entryValue = entry.getValue(); if (entryValue == null) { continue; // Skip null values. } // hack by wesley wu start // support multivaluemap if (entryValue instanceof Collection) { Collection valueCollection = (Collection) entryValue; for (Object valueOne : valueCollection) { addPart(builder, entryKey, valueOne); } } else { addPart(builder, entryKey, entryValue); } // hack by wesley wu end } } private void addPart(RequestBuilder builder, Object entryKey, Object entryValue) { Headers headers; Class<?> entryClass = entryValue.getClass(); //noinspection unchecked Converter<Object, RequestBody> converter = retrofit.requestConverter(entryClass, annotations); RequestBody body; try { body = converter.convert(entryValue); } catch (IOException e) { throw new RuntimeException("Unable to convert " + entryValue + " to RequestBody", e); } // dirty hack by wesley wu start if (BINARY_TYPE.contains(body.contentType().type())) { headers = Headers.of( "Content-Disposition", "form-data; name=\"" + entryKey + "\"; filename=\"" + entryKey + "\"", "Content-Transfer-Encoding", transferEncoding); } else { headers = Headers.of( "Content-Disposition", "form-data; name=\"" + entryKey + "\""); } // dirty hack by wesley wu end builder.addPart(headers, body); } }
The text was updated successfully, but these errors were encountered:
duplicated with #1140. Please ignore this :)
Sorry, something went wrong.
Dupe #1140.
No branches or pull requests
PartMap should add filename to each file part, because many Java servlet container treat part as an upload file only by the filename attribute.
Also, the Content-Transfer-Encoding header is useless.
I hacked the PartMap impl
The text was updated successfully, but these errors were encountered: