-
Notifications
You must be signed in to change notification settings - Fork 552
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
post multipart entity error #161
Comments
Huh? |
fixed method newProxyRequestWithEntity private HttpRequest newProxyRequestWithEntity(
String method,
String proxyRequestUri,
HttpServletRequest servletRequest,
boolean isMultipart
) throws IOException, ServletException {
HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(method, proxyRequestUri);
HttpEntity entity;
if (isMultipart) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
StandardMultipartHttpServletRequest multipart = (StandardMultipartHttpServletRequest) servletRequest;
Collection<Part> parts = multipart.getParts();
for (Part part : parts) {
String name = part.getName(), fileName = part.getSubmittedFileName();
if (fileName == null) {
builder.addPart(name, new PartBody(part.getInputStream(), ContentType.MULTIPART_FORM_DATA, part.getSize()));
} else {
builder.addPart(name, new PartBody(part.getInputStream(), fileName, part.getSize()));
}
}
entity = builder.build();
} else {
entity = new InputStreamEntity(servletRequest.getInputStream(), getContentLength(servletRequest));
}
request.setEntity(entity);
return request;
}
public class PartBody extends InputStreamBody {
private long size;
public PartBody(InputStream in, ContentType contentType, long size) {
super(in, contentType);
this.size = size;
}
public PartBody(InputStream in, String filename, long size) {
super(in, filename);
this.size = size;
}
@Override
public long getContentLength() {
return size;
}
} StandardMultipartHttpServletRequest Refer to the checkMultipart method of DispatcherServlet |
I don't know where the code you refer to is. Perhaps submit a PR and failing test that this will fix, if you would like it accepted. |
Hi Maxid, looks like your solution requires Spring? That's an extra dependency, right? Won't work for me, I'm not using Spring! I think StandardMultipartHttpServletRequest is from Spring? |
Hi dsmiley: [2020-05-25 16:34:52] [ERROR] [http-nio-8081-exec-1] [/] [c.i.p.s.c.e.BaseExceptionHandler:baseError:20] BaseException报错: {} |
maxid: |
这个问题解决了吗? |
PR welcome, especially one that includes a test that fails without the fix. |
I'm struggelig with the same issue. Looks like Multipart requests are not very well supported. I have an issue where the server I'm calling is surpose to return an 403 error when about to upload a large file. Are you actually able to get the parts when calling multipart.getParts()? |
Looks like the cause for my issue is that httpcomponents-core 4.4.x does not support out-of-order responses, where we look for error response before the entity entity is uploaded. Apparently this feature has been implemented in httpcomponents-core 5.1 |
i found an error, missing multipart processing logic. like this:
if (ServletFileUpload.isMultipartContent(httpServletRequest)) {
this.handleMultipart(postMethodProxyRequest, httpServletRequest);
} else {
this.handleStandard(postMethodProxyRequest, httpServletRequest);
}
The text was updated successfully, but these errors were encountered: