简体   繁体   中英

Additional info at file upload with playframework

How can i pass additional info in my file uploading request:

My action looks like this:

public static Result upload() {
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart picture = body.getFile("picture");
...

and this is my view:

@form(action = routes.Application.upload, 'enctype -> "multipart/form-data") {
        <input type="file" name="picture">
        <p>
            <input type="submit">
        </p>
    }

As far as i understand it would be no prblem to add another image to the request, but i want to add some other information (the id of the item which the uploaded picture belongs to, otherwise its worthless...) to the request.

Tried it with a hidden input field, but could not retrieve the value in my action.

Thanks for any proposal.

I did it like this:

MultipartFormData body = request().body().asMultipartFormData();
List<FilePart> files = body.getFiles();
// store files etc.
Map<String, String[]> asFormUrlEncoded = request().body().asMultipartFormData().asFormUrlEncoded();
String[] descriptionParams  = asFormUrlEncoded.get("description");
// save descriptions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM