如何从MultipartHttpServletRequest对象获取文件的内容? [英] How to get file contents from a MultipartHttpServletRequest object?
问题描述
我想使用此策略网页上传的文件。即的Ajax文件上传教程。这是怎么回事都很好,但问题是在服务器端,在这里我想打开此文件并阅读其内容。 我使用下面的签名被称为在表格的提交方式。 即
I would like to upload a file from the web page using this strategy. i.e. Ajax file upload tutorial . It is going all fine, but the issue is on the server side, where I want to open this file and read its contents. I am using the following signature for the method which is called on the submit of the form. i.e.
公共@ResponseBody字符串的getFile(MultipartHttpServletRequest要求)
任何机构可以请让我知道,我怎么能提取该文件的内容是什么?
Can any body please let me know that how can I extract the contents of the file?
推荐答案
MultipartHttpServletRequest延伸MultipartRequest,其中有用于访问文件的方法。
MultipartHttpServletRequest extends MultipartRequest, which has methods for accessing the files.
您可以这样做:
MultipartFile file = request.getFile(paramName);
请参阅<一href="http://docs.spring.io/spring-framework/docs/3.2.0.M1/api/org/springframework/web/multipart/MultipartRequest.html" rel="nofollow">http://docs.spring.io/spring-framework/docs/3.2.0.M1/api/org/springframework/web/multipart/MultipartRequest.html
这篇关于如何从MultipartHttpServletRequest对象获取文件的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!