Probably the quickest way for you now is to simply make a copy of the
relevant Form plugin, name it something else, and just change the
enctype.
Also please put in a JIRA request for the enctype to be changeable,
and we'll snatch it in either 2.8.1 or 3.0.
/Janne
On Fri, Oct 10, 2008 at 10:50:32AM +0200, Benedikt Mohrmann wrote:
> Hi,
>
> just checked it again.
> The problem is definetely the form:
> org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException:
> the request doesn't contain a multipart/form-data or multipart/mixed
> stream, content type header is application/x-www-form-urlencoded
>
> Pretty bad that you can not change the enctype.
> In the Wiki Src it is:
> tag.append( "\" method=\""+method+"\"
> enctype=\"application/x-www-form-urlencoded\">\n" );
>
> Can't I just change this?
>
> Another way could be to write a plugin with the following code (snippet):
> returnStringBuffer.append("<div class=\"wikiform\">");
> returnStringBuffer.append("<form action=\"Wiki.jsp?page=MyTest\"
> name=\"uploadForm\" accept-charset=\"UTF-8\" method=\"post\"
> enctype=\"multipart/form-data\">");
> returnStringBuffer.append("<input type=\"hidden\"
> name=\"formname\" value=\"uploadForm\"/>");
> returnStringBuffer.append("<input name=\"nbz_Datei\"
> type=\"file\"><input type=\"submit\" name=\"nbz_upload\" id=\"upload\"
> value=\"Hochladen\" />");
> returnStringBuffer.append("</form></div>");
>
> This would create a form, but how can I tell the Wiki which plugin to
> use, when the button is hit?
>
> Regards
> Benedikt
>
>
> Janne Jalkanen schrieb:
> >
> >I think it is important to look into the cause... The stack trace
> >would be important, yes. There could be many things failing.
> >
> >/Janne
> >
> >On Oct 9, 2008, at 19:15 , Harry Metske wrote:
> >
> >>I think so too (multipart/form-data), but can you print the
> >>stacktrace just
> >>before returning " BUG" , maybe you'll get a clue then ?
> >>
> >>The FormOpen class currently has a hardcoded
> >>"application/x-www-form-urlencoded", I think this should be
> >>parameterizable
> >>with the current value as the default.
> >>
> >>
> >>regards,
> >>Harry
> >>
> >>
> >>2008/10/9 Benedikt Mohrmann <[EMAIL PROTECTED]>
> >>
> >>>Hi,
> >>>
> >>>I tried a few things already, but did not get it to work so far.
> >>>
> >>>At first I created a new site, which contains:
> >>>[{FormSet form='searchForm'}]
> >>>[{FormOpen form='searchForm'}]
> >>>[{FormInput type='file' name='searchInput'}]
> >>>
> >>>[{FormInput type='submit' name='submit' value='Submit'}]
> >>>[{FormClose}]
> >>>[{FormOutput form='searchForm' handler='MyTest2'}]
> >>>
> >>>Thus there is only a form where you can upload your data.
> >>>
> >>>The Plugin contains the following code (at this time really simple,
> >>>just to
> >>>check if it works):
> >>>public class MyTest2 implements WikiPlugin {
> >>>
> >>> @Override
> >>> public String execute(WikiContext context, Map params) throws
> >>>PluginException {
> >>> HttpServletRequest request = context.getHttpRequest();
> >>> boolean isMultipart =
> >>>ServletFileUpload.isMultipartContent(request);
> >>> // Create a factory for disk-based file items
> >>> FileItemFactory factory = new DiskFileItemFactory();
> >>>
> >>> // Create a new file upload handler
> >>> ServletFileUpload upload = new ServletFileUpload(factory);
> >>>
> >>> // Parse the request
> >>> List<FileItem> items = null;
> >>> try {
> >>> items = upload.parseRequest(request);
> >>> } catch (Exception e) {
> >>> // TODO Auto-generated catch block
> >>> return "BUG";
> >>> }
> >>> return "Works";
> >>> }
> >>>}
> >>>
> >>>So far I always get the "BUG" output when I choose a file and hit the
> >>>submitbutton.
> >>>One problem could be that when I take a look at the produced HTML
> >>>code, the
> >>>form is introduced with:
> >>>
> >>><form action="Wiki.jsp?page=MyTest" name="searchForm"
> >>>accept-charset="UTF-8" method="post"
> >>>enctype="application/x-www-form-urlencoded">
> >>>
> >>>I think it should be the enctype: multipart/form-data
> >>>But I don't know if that is the point.
> >>>
> >>>Any other ideas?
> >>>
> >>>
> >>>Best regards
> >>>Benedikt
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>Harry Metske schrieb:
> >>>
> >>>>my previous answer was a bit too much in a hurry....
> >>>>
> >>>>first your compile, Eclipse tells you there is no method
> >>>>getHttpRequest
> >>>>for
> >>>>a wiki context, that is strange, looking at the source it does have
> >>>>it :
> >>>>
> >>>>........
> >>>> /**
> >>>> * If the request did originate from a HTTP request,
> >>>> * then the HTTP request can be fetched here. However, it the
> >>>>request
> >>>> * did NOT originate from a HTTP request, then this method will
> >>>> * return null, and YOU SHOULD CHECK FOR IT!
> >>>> *
> >>>> * @return Null, if no HTTP request was done.
> >>>> * @since 2.0.13.
> >>>> */
> >>>> public HttpServletRequest getHttpRequest()
> >>>> {
> >>>> return m_request;
> >>>> }
> >>>>.......
> >>>>
> >>>>and if you can't compile it, I shouldn't even try to run it.
> >>>>Maybe you can reply the complete source of your plugin ?
> >>>>
> >>>>regards,
> >>>>Harry
> >>>>
> >>>>2008/10/8 Benedikt Mohrmann <[EMAIL PROTECTED]>
> >>>>
> >>>>
> >>>>
> >>>>>Hi,
> >>>>>
> >>>>>thanks for your answer- I already had a look at commons fileupload.
> >>>>>But the problem is, when I use:
> >>>>>
> >>>>>HttpServletRequest request = context.getHttpRequest();
> >>>>>
> >>>>>JSPWiki tells me
> >>>>>
> >>>>>HttpServletRequest cannot be resolved to a type
> >>>>> The type javax.servlet.http.HttpServletRequest cannot be resolved.
> >>>>>
> >>>>>In addition I am implementing my plugin in Eclipse and it tells me
> >>>>>that
> >>>>>there is no method getHttpRequest for a wiki context.
> >>>>>
> >>>>>Best regards
> >>>>>Benedikt
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>Harry Metske schrieb:
> >>>>>
> >>>>> Benedikt,
> >>>>>
> >>>>>
> >>>>>>in your plugin you have access to the HttpServletRequest (
> >>>>>>HttpServletRequest request = context.getHttpRequest(); ) .
> >>>>>>Once you have this, I think you can use many samples/tools to
> >>>>>>handle the
> >>>>>>uploaded file, but maybe the best one is commons fileupload (
> >>>>>>http://commons.apache.org/fileupload/using.html), this binary jar is
> >>>>>>already
> >>>>>>in the JSPWiki distribution.
> >>>>>>
> >>>>>>regards,
> >>>>>>Harry
> >>>>>>
> >>>>>>2008/10/7 Benedikt Mohrmann <[EMAIL PROTECTED]>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>>Hi,
> >>>>>>>
> >>>>>>>my intention is to upload a file via JSPWiki, but not as an
> >>>>>>>attachment.
> >>>>>>>
> >>>>>>>I am trying to upload a file, thus I created a form containing a
> >>>>>>>file
> >>>>>>>chooser and a submitbutton.
> >>>>>>>The goal is, that the input file is transferred to the server
> >>>>>>>and then
> >>>>>>>handled by a plugin I wrote.
> >>>>>>>
> >>>>>>>The plugin just puts the file as a Serializable into a database
> >>>>>>>(which
> >>>>>>>already works, when I read a file from my harddisk).
> >>>>>>>But I am not yet not able to transfer the content of the file as a
> >>>>>>>stream
> >>>>>>>or something like that.
> >>>>>>>
> >>>>>>>Any experiences how this could work?
> >>>>>>>
> >>>>>>>Best regards
> >>>>>>>Benedikt
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >