0

I'm currently using Wicket and a jQuery plugin to crop picture ("croppic") and it need to request with ajax my back-end to crop the picture. The data are sent in a multipart format.

My Wicket back-end is an Ajax behavior with the "onRequest" method and I don't know how to retrieve the multipart data.

@Override
public void onRequest() {
    String json = "{}";
    boolean hasError = false;

    RequestCycle cycle = getComponent().getRequestCycle();
    IRequestParameters parameters =     cycle.getRequest().getPostParameters();

This code only access to classic POST variables but cannot used to multipart form data (values are empty).

Do you know how to proceed for that?

PS: this thread is helpful but not understandable for me : Wicket 6 - Capturing HttpServletRequest parameters in Multipart form?

The body payload:

------WebKitFormBoundarykpVsQAYFGJywlAZd
Content-Disposition: form-data; name="imgUrl"

https://scontent.xx.fbcdn.net/hprofile-xpf1/t31.0-        1/c0.0.1536.1536/13055008_225242101175595_5770204993752392511_o.jpg
------WebKitFormBoundarykpVsQAYFGJywlAZd
Content-Disposition: form-data; name="imgInitW"

1536
------WebKitFormBoundarykpVsQAYFGJywlAZd
Content-Disposition: form-data; name="imgInitH"

1536
------WebKitFormBoundarykpVsQAYFGJywlAZd
Content-Disposition: form-data; name="imgW"

500
------WebKitFormBoundarykpVsQAYFGJywlAZd
Content-Disposition: form-data; name="imgH"

500
------WebKitFormBoundarykpVsQAYFGJywlAZd
Content-Disposition: form-data; name="imgY1"

etc...

Community
  • 1
  • 1
christophedebatz
  • 184
  • 3
  • 16

2 Answers2

1

Try with:

WebRequest webRequest = (WebRequest) cycle.getRequest();
MultipartServletWebRequest multiPartRequest = webRequest.newMultipartWebRequest(getMaxSize(), "ignored");
multiPartRequest.parseFileParts();
IRequestParameters params = multiPartRequest.getRequestParameters();
martin-g
  • 17,243
  • 2
  • 23
  • 35
0

Here is my final code that works... very ugly but it works properly.

@Override
public void onRequest() {
    boolean hasError = false;
    IRequestParameters parameters = null;
    RequestCycle cycle = RequestCycle.get();
    ServletWebRequest webRequest = (ServletWebRequest) cycle.getRequest();

    try {
        MultipartServletWebRequest multiPartRequest = webRequest.newMultipartWebRequest(Bytes.kilobytes(10), "ignored");
        multiPartRequest.parseFileParts();
        parameters = multiPartRequest.getRequestParameters();

    } catch (FileUploadException e) {
        hasError = true;
    }

After that you can easily call :

parameters.getParameterValue("you_param");
christophedebatz
  • 184
  • 3
  • 16