Play 2.4 Missing Boundary Header error on File upload

2,076 views
Skip to first unread message

Gaurav Kalmady

unread,
Jul 7, 2015, 4:13:54 PM7/7/15
to play-fr...@googlegroups.com
Hi,
  I am using an app written in playframework 2.4. The app is a file receiver and processor that is supposed to receive the files via post requests. I sent a tar.gz file via curl and ensured that the request verb was POST and the headers contained "Content-Type:multipart/form-data"
This is what my curl request looks like
 
curl -k -H "token:a" -H "Content-Type:multipart/form-data" --request POST http://localhost:9000/receivefile --data @testdata.tar.gz

I consistently get a
[error] c.v.l.ErrorHandler -
[error] c.v.l.ErrorHandler -
[error] c.v.l.ErrorHandler - Missing boundary header

This error is emitted by the configured ErrorHandler before any business logic is hit.

This is what is invoked in the ErrorHandler with an empty message

    @Override
    public Promise<Result> onClientError(RequestHeader request, int statusCode, String message) {
        Logger.of(this.getClass()).error(message);

        ObjectNode result = Json.newObject();
        result.put("statusCode", statusCode);
        result.put("message", message);
        return Promise.<Result>pure(play.mvc.Results.badRequest(result));
    }


What am I missing to allow the file to upload successfully? The file is a genuine tar.gz file that works with other applications.

Thanks
Gaurav

Gaurav Kalmady

unread,
Jul 7, 2015, 4:21:03 PM7/7/15
to play-fr...@googlegroups.com
Some additional information.

My routes file looks like this
POST    /receiveFiles         com.testapp.controllers.Application.receiveFiles()

Marcos Pereira

unread,
Jul 7, 2015, 5:23:00 PM7/7/15
to play-framework
Gaurav,

I think this is a problem with your curl command. You are trying to use "multipart/form-data", but --data will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. See the docs:

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.

If you want to emulate what the browser is doing, try -F, --form as indicated by curl docs:

You can't simply use -F or -d at your choice. The web server that will receive your post expects one of the formats. If the form you're trying to submit uses the type 'multipart/form-data', then and only then you must use the -F type. In all the most common cases, you should use -d which then causes a posting with the type 'application/x-www-form-urlencoded'.

So, your curl command must looks like this:

curl -i -v -k -H "token:a" -F "someInput=valueOfSomeInput" -F "fileInput=@/home/user1/Desktop/test.jpg" http://localhost:9000/receivefile

I've purposely add some "debug" options (-i and -v) so you can better see what is happening.

Best,

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/af035981-fa46-4a04-9f92-1219ae8371bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages