Last active
August 29, 2015 14:16
-
-
Save nherbaut/0ec0d5c3654de7281dea to your computer and use it in GitHub Desktop.
uploading binary data jersey
This file contains hidden or 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 | |
| @Consumes(MediaType.APPLICATION_OCTET_STREAM) | |
| @Produces(MediaType.TEXT_PLAIN) | |
| public String postIf(InputStream is) throws IOException, SAXException, | |
| TikaException { | |
| java.nio.file.Path path = Files.createTempFile(null, null); | |
| FileOutputStream fos = new FileOutputStream(path.toFile()); | |
| ByteStreams.copy(is, fos); | |
| fos.close(); | |
| is.close(); | |
| TikaConfig config = TikaConfig.getDefaultConfig(); | |
| Detector detector = config.getDetector(); | |
| TikaInputStream stream = TikaInputStream.get(path.toFile()); | |
| Metadata metadata = new Metadata(); | |
| metadata.add(Metadata.RESOURCE_NAME_KEY, path.toString()); | |
| org.apache.tika.mime.MediaType mediaType = detector.detect(stream, | |
| metadata); | |
| return mediaType.toString() + " -- " + path.toString(); | |
| } | |
| /* | |
| nherbaut@nheraut-HP-EliteBook-840-G1:~/Downloads$ curl http://localhost:8080/myapp/myresource -X POST -H "Content-type: application/octet-stream" --data-binary @salt.epub | |
| application/epub+zip -- /tmp/7966734083095282602.tmp | |
| nherbaut@nheraut-HP-EliteBook-840-G1:~/Downloads$ curl http://localhost:8080/myapp/myresource -X POST -H "Content-type: application/octet-stream" --data-binary @Parks.and.Recreation.S05E03.HDTV.x264-LOL.mp4 | |
| video/quicktime -- /tmp/310716347147553547.tmp) | |
| nherbaut@nheraut-HP-EliteBook-840-G1:~/Downloads$ curl http://localhost:8080/myapp/myresource -X POST -H "Content-type: application/octet-stream" -d @Mini-FTP.tar.zip application/zip -- /tmp/7605619278719341932.tmp | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment