Last active
August 29, 2015 14:24
-
-
Save lefloh/c9bc852596c7f1a8b71e to your computer and use it in GitHub Desktop.
RESTesy resource guessing the encoding
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
@POST | |
@Path("/form") | |
@Consumes(MediaType.MULTIPART_FORM_DATA) | |
@Produces(MediaType.TEXT_PLAIN) | |
public Response uploadForm(MultipartFormDataInput input) throws IOException { | |
String charset = input.getFormDataMap().get("_charset_").get(0).getBodyAsString(); | |
InputPart file = input.getFormDataMap().get("file").get(0); | |
InputStream inputStream = file.getBody(InputStream.class, null); | |
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, charset)); | |
String line; | |
StringBuilder content = new StringBuilder(); | |
while ((line = br.readLine()) != null) { | |
content.append(line); | |
} | |
return Response.ok(content).header("Content-Type", MediaType.TEXT_PLAIN_TYPE.withCharset(charset)).build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment