I do not know which libraries meet your requirements. But if you don't mind doing some kind of coding, I think a good way to create something like this is to write your own
public class FileMessageConverter extends AbstractHttpMessageConverter<File>
which converts the request body to a file in the tmp directory:
@Override protected File readInternal(Class<? extends File> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { InputStream inputStream = inputMessage.getBody(); File tmpFile = File.createTempFile("upload","tmp"); if (inputStream != null) { FileOutputStream outputStream = new FileOutputStream(tmpFile); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); outputStream.close(); } return tmpFile; }
In the controller, you define your method with:
@RequestMapping(value="/{fileName}", method = RequestMethod.PUT) public ResponseEntity uploadFile(@PathVariable(value="fileName") String fileName, @RequestBody File tmpFile) throws IOException { // .. process tmpFile, eg tmpFile.renameTo(new File(fileName); return new ResponseEntity<String>(HttpStatus.CREATED); }
Remember to register your FileMessageConverter, for example
@Configuration @EnableWebMvc @ComponentScan(basePackages = {"my.controller.package"}) public class WebConfig extends WebMvcConfigurerAdapter { @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { converters.add(new FileMessageConverter()); } }
The curl command to invoke the boot:
curl -v -X PUT -T "myfile" http:
source share