Skip to content

Instantly share code, notes, and snippets.

@robshep
Last active August 29, 2015 14:11
Show Gist options
  • Save robshep/8f03c66976c0eaa4eafd to your computer and use it in GitHub Desktop.
Save robshep/8f03c66976c0eaa4eafd to your computer and use it in GitHub Desktop.
/**
* simple groovy server using spring boot
*
* spring run script.groovy
*
* uses:
*
* https://spring.io/blog/2013/08/06/spring-boot-simplifying-spring-for-everyone
* http://spring.io/guides/gs/uploading-files/
*
* Notes:
*
* put a folder called public/ next to the script to serve raw html/img assets
*/
import org.springframework.boot.context.embedded.MultipartConfigFactory;
import javax.servlet.MultipartConfigElement;
import org.springframework.web.multipart.MultipartFile;
@Controller
class ThisWillActuallyRun {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello Worlds!"
}
@RequestMapping(value="/post", method=RequestMethod.POST)
@ResponseBody
String post(@RequestParam("file") MultipartFile file){
println file.name
println file.contentType
File dest = File.createTempFile("temp-image", "tmp");
file.transferTo(dest)
println dest
//println lat + " " + lon
}
@Configuration
public static class Config{
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("128MB");
factory.setMaxRequestSize("128MB");
return factory.createMultipartConfig();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment