Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Context param provider can handle multipart uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
petenattress committed Jun 23, 2017
1 parent ca7000c commit 70b7743
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/components/common/state/ContextParamProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static play.mvc.Controller.ctx;

import org.apache.commons.lang3.StringUtils;
import utils.common.UploadUtil;

import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -32,7 +33,12 @@ private static String getParamValueFromRequest(String paramName, boolean strict)
}
else {
//Check POST params
Map<String, String[]> postParamMap = ctx().request().body().asFormUrlEncoded();
Map<String, String[]> postParamMap;
if (UploadUtil.isMultipartRequest(ctx().request())) {
postParamMap = ctx().request().body().asMultipartFormData().asFormUrlEncoded();
} else {
postParamMap = ctx().request().body().asFormUrlEncoded();
}

if (postParamMap == null) {
if (strict) {
Expand Down
11 changes: 11 additions & 0 deletions app/utils/common/UploadUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package utils.common;

import play.mvc.Http;

public class UploadUtil {

public static boolean isMultipartRequest(Http.Request request) {
return "multipart/form-data".equals(request.contentType().orElse(""));
}

}

0 comments on commit 70b7743

Please sign in to comment.