Problem writing UserProperty extension with a 'file' type input

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem writing UserProperty extension with a 'file' type input

0xcafebabe
I'm trying to write a UserProperty that allows a file to be uploaded
from the local machine and attached to the User.

I've found that if my config.jelly contains something like:
<f:entry title="Upload" description="Upload new file">
        <input type="file" jsonAware="yes" />
</f:entry>

Then in my reconfigure(StaplerRequest req, JSONObject form) method I
can pick up the fileItem and get hold of the file.

Unfortunately though this breaks the updates to the fullName and
description properties of the User.

In the doConfigSubmit() method of User, the fullName and description
properties are updated from request parameters:
        fullName = req.getParameter("fullName");
        description = req.getParameter("description");

and these are null when my 'file' input is on the page. This corrupts
the User object and Jenkins must be restarted to recover. These
properties are present in the JSON form, so I'm wondering why the code
gets them out of parameters.

I would guess the problem is due to the form being an unexpected
multipart/form-data type, and the request doesn't correctly process it
into parameters.

I've spent a very long time getting to this point by stepping through
source code, and now I can't work out how to get around it.

Can anyone help please?
Reply | Threaded
Open this post in threaded view
|

Re: Problem writing UserProperty extension with a 'file' type input

Alan Harder-2
I'm sure the use of "getParameter" is just there because the code is very
old.. if changing that to use json data fixes your problem, I'm sure that
patch would be accepted into core.

Alternatively, if it helps, here is an example of doing a file upload in an
iframe to make it a separate request from the rest of the page:
https://github.com/jenkinsci/sidebar-link-plugin/commit/3b676df0e658467cba764b618053d58e882c4c4c
and small followup fix:
https://github.com/jenkinsci/sidebar-link-plugin/commit/88e634db7276e8736e54d674a6d99eec19aef9f8

   - Alan


On 4/24/11 6:45 AM, 0xcafebabe wrote:

> I'm trying to write a UserProperty that allows a file to be uploaded
> from the local machine and attached to the User.
>
> I've found that if my config.jelly contains something like:
> <f:entry title="Upload" description="Upload new file">
> <input type="file" jsonAware="yes" />
> </f:entry>
>
> Then in my reconfigure(StaplerRequest req, JSONObject form) method I
> can pick up the fileItem and get hold of the file.
>
> Unfortunately though this breaks the updates to the fullName and
> description properties of the User.
>
> In the doConfigSubmit() method of User, the fullName and description
> properties are updated from request parameters:
>          fullName = req.getParameter("fullName");
>          description = req.getParameter("description");
>
> and these are null when my 'file' input is on the page. This corrupts
> the User object and Jenkins must be restarted to recover. These
> properties are present in the JSON form, so I'm wondering why the code
> gets them out of parameters.
>
> I would guess the problem is due to the form being an unexpected
> multipart/form-data type, and the request doesn't correctly process it
> into parameters.
>
> I've spent a very long time getting to this point by stepping through
> source code, and now I can't work out how to get around it.
>
> Can anyone help please?