cancel
Showing results for 
Search instead for 
Did you mean: 

How to access request content using MultipartMessage Object

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

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!

Answers (2)

Answers (2)

Former Member
0 Kudos

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.

detlev_beutner
Active Contributor
0 Kudos

Hi Mat,

yes, sounds a bit like this. But also in this case, this would sound like a violation of the servlet specification (not sure about it, but seems at least probable) and therefore an OSS message should be opened.

Hope it helps

Detlev

Former Member
0 Kudos

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?

detlev_beutner
Active Contributor
0 Kudos

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:

http://servlets.com/cos/

or

http://jakarta.apache.org/commons/fileupload/

Hope it helps

Detlev