Last active
June 28, 2016 19:56
-
-
Save oksuz/3bfe382092a2ebac57ec44e30e88d5f0 to your computer and use it in GitHub Desktop.
It can't upload file to apache2.2/php-fcgi, but it works with nginx/php5-fpm well
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Response fileUpload(URL url, String fieldName, String fileName, InputStream content, List<BasicNameValuePair> params, List<Header> headers) throws IOException { | |
HttpClient client = getHttpClient(); | |
HttpPost post = new HttpPost(url.toString()); | |
if (null != headers) { | |
for (Header h : headers) { | |
post.addHeader(h); | |
} | |
} | |
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); | |
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); | |
if (null != params) { | |
for (NameValuePair pair : params) { | |
entityBuilder.addPart(pair.getName(), new StringBody(pair.getValue(), ContentType.TEXT_PLAIN)); | |
} | |
} | |
entityBuilder.addBinaryBody(fieldName, content, ContentType.DEFAULT_BINARY, fileName); | |
post.setEntity(entityBuilder.build()); | |
if (null != context) { | |
return new Response(client.execute(post, context)); | |
} | |
return new Response(client.execute(post)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I replaced
It worked fuuu!!!