resteasy服务器代码
@Path(value = "file") public class UploadFileService { private final String UPLOADED_FILE_PATH = "d:\\resteasy\\"; @POST @Path(value = "/upload") @Consumes("multipart/form-data") public Response uploadFile(MultipartFormDataInput input) { String fileName = ""; Map<String, List<InputPart>> uploadForm = input.getFormDataMap(); List<InputPart> inputParts = uploadForm.get("file_upload"); for (InputPart inputPart : inputParts) { try { MultivaluedMap<String, String> header = inputPart.getHeaders(); fileName = getFileName(header); //convert the uploaded file to inputstream InputStream inputStream = inputPart.getBody(InputStream.class,null); byte [] bytes = IOUtils.toByteArray(inputStream); //constructs upload file path fileName = UPLOADED_FILE_PATH + fileName; writeFile(bytes,fileName); } catch (IOException e) { e.printStackTrace(); } } return Response.status(200) .entity("uploadFile is called, Uploaded file name : " + fileName).build(); } private String getFileName(MultivaluedMap<String, String> header) { String[] contentDisposition = header.getFirst("Content-Disposition").split(";"); for (String filename : contentDisposition) { if ((filename.trim().startsWith("filename"))) { String[] name = filename.split("="); String finalFileName = name[1].trim().replaceAll("\"", ""); return finalFileName; } } return "unknown"; } //save to somewhere private void writeFile(byte[] content, String filename) throws IOException { File file = new File(filename); if (!file.exists()) { file.createNewFile(); } FileOutputStream fop = new FileOutputStream(file); fop.write(content); fop.flush(); fop.close(); } }
客户端代码
<form action="http://localhost:8080/resteay-server/file/upload/" method="post" enctype="multipart/form-data"> <input type="file" name="file_upload"> <input type="submit" value="提交"> </form>
相关推荐
使用RESTEasy+guice实现上传下载文件
resteasy上传功能资料 都是网上搜集的一些代码demo 方便学习入门
resteasy
Spring整合RestEasy示例工程源码,Spring+Jetty+RestEasy
resteasy不使用tomcat使用netty实现,实现了高性能,也可以不需要tomcat的容器,一个主函数就能执行
详细描述了restEasy在servlet3.0前后的不同使用方法;restEasy 结合httpServer 无需容器开发;restEasy的通用差错拦截;附详细实现源码!
该资源是java restful的应用框架resteasy---实现了jax-rs规范的一个demo,如有疑问请联系caizhh2009@gmail.com
resteasy讲解
RESTEasy 项目是 JAX-RS 的一个实现,集成的一些亮点: * 不需要配置文件,只要把JARs文件放到类路径里面,添加 @Path 注解就可以了。 * 完全的把 RESTEeasy 配置作为Seam 组件来看待。 * HTTP 请求由Seam来提供...
resteasy入门级文档、如何使用Restful进行WebService的开发简介及相关RestEasy相关资源的链接
resteasy简单demo使用的jar包
RESTEasy入门经典.docx
Resteasy + Spring + Netty sample Inject resteasy provider / controllers as spring bean Authentication Run at Main.java Test http://localhost:8082/resteasy/hello/world 教程 jax-rs规范用法: ...
resteasy-jaxrs-2.3.2框架源码。希望您了解Resteasy框架有所帮助
RESTEasy JSON DEMO
resteasy参考文档及jar包
Resteasy英文文档,开发rest风格的API接口
resteasy-reference-guide-en-US.pdf
介绍了RESTEasy中的安全机制的使用方法
resteasy在jboss7.1中的使用介绍,源代码,两种方式,自动注册rest service以及在程序中实现