on 01-18-2006 7:10 PM
I want to take a file from the Client and upload it as a FileInputStream on the server.
I have a simple form as follows:
<form action="scan" name="scan_files" method="post"
enctype="multipart/form-data">
<input type="file" name="file1">
<input type="file" name"file2"/>
<input type="Submit" name="insert_scaned" value="Upload"/>
</form>
In my servlet I tried to use the com.sap.engine.services.servlets_jsp.lib.multipart.MultipartMessage
class to parse the form information.
protected void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
MultipartMessage multipartMsg =
(MultipartMessage)request.getAttribute("com.sap.servlet.multipart.body");
if (multipartMsg != null) {
multipartMsg.addFormParametersToRequest();
}
The help said that once this is done the form information should be accessible via the
request getParameter() method. However, I can't seem to get it working?
How can I access the file so that I can parse it into a FileInputStream?
Thanks.
Hi Mat,
first, welcome on SDN!
About your question:
From the APIDoc - https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/javadocs/nw04/sp12/j2ee%20engine... - I would expect this as a solution:
MultipartMessage multipartMsg = (MultipartMessage)request.getAttribute(MultipartMessage.MULTIPART_BODY_KEY);
if (multipartMsg != null) {
for (int i = 0; i < multipartMsg.getCount(); i++) {
MultiPart mp = multipartMsg.getBodyPart(i);
// mp.getInputStream, mp.getBody() or whatever you need
}
}
Hope it helps
Detlev
PS: Please consider rewarding points for helpful answers on SDN. Thanks in advance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried the jakarta commons fileupload package. It was one of the first things I attempted. However, when I implemented that, the parseRequest() method didn't return any items.
I'm starting to think that my not being able to parse in the file might have something to do with the server and the way the information is being passes to the servlet. I'm just not sure where to look.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've tried that approach. I used this help site.
<a href="http://help.sap.com/saphelp_nw04/helpdata/de/ff/4a367dc596a3468d417aa51ad7bcd3/content.htm">http://help.sap.com/saphelp_nw04/helpdata/de/ff/4a367dc596a3468d417aa51ad7bcd3/content.htm</a>
But when I ran the code from the help (which is similar to what you suggested), I get an exception.
com.sap.engine.services.servlets_jsp.lib.multipart.MultipartParseException: Start boundary not found.
Which based on the help page above I think is happening because I'm using multipart/form-data.
Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mat,
this sounds like a bug. I would definitely open an OSS message for that. In addition, you could try to use one of the alternative multipart parsing classes:
or
http://jakarta.apache.org/commons/fileupload/
Hope it helps
Detlev
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.