Java 如何从 MultipartHttpServletRequest 对象获取文件内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20674965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get file contents from a MultipartHttpServletRequest object?
提问by Ch Faizan Mustansar
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.
我想使用此策略从网页上传文件。即Ajax 文件上传教程。一切顺利,但问题出在服务器端,我想在其中打开此文件并读取其内容。我对提交表单时调用的方法使用以下签名。IE
public @ResponseBody String getFile(MultipartHttpServletRequest request)
public @ResponseBody String getFile(MultipartHttpServletRequest request)
Can any body please let me know that how can I extract the contents of the file?
任何机构都可以让我知道如何提取文件的内容?
采纳答案by Pieter
MultipartHttpServletRequest extends MultipartRequest, which has methods for accessing the files.
MultipartHttpServletRequest 扩展了 MultipartRequest,它具有访问文件的方法。
You can do this:
你可以这样做:
MultipartFile file = request.getFile(paramName);