Search code examples
web-servicesspring-bootamazon-s3cloud-foundrypredix

CommonsMultipartFile or MultipartFile not working once pushed into cloudfoundry


I am trying to upload a file using CommonsMultipartFile or MultipartFile and its working fine in local but not working once pushed into cloudfoundry.

I am testing using Postman.

Here is the sample code:

@ResponseBody    
    @RequestMapping(value = "/api/stw/upload1", method = RequestMethod.POST)
    public String upload1(@RequestParam(name="text",required=true) MultipartFile text){

        return "done";

    }

Here is the response in Postman when I am trying to call CF URL.

{
  "timestamp": 1494397075418,
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.web.bind.MissingServletRequestParameterException",
  "message": "Required MultipartFile parameter 'text' is not present",
  "path": "/api/stw/upload1"
}

Note: I am passing in form-data the key value required in postman.Its working on local but not on CF. eg: text(Key) - uploadfile(Value)

    **Request Header**

    Accept:*/*
    Accept-Encoding:gzip, deflate, br
    Accept-Language:en-US,en;q=0.8,kn;q=0.6
    Cache-Control:no-cache
    Connection:keep-alive
    Content-Length:32354
    Content-Type:multipart/form-data; boundary=----WebKitFormBoundary10QktAWiD1GCsBKF
    DNT:1
    Host:<CF Service URL>
    Origin:chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
    Postman-Token:d22500e6-f0d9-0f29-b981-78a45b6e4524
    Pragma:no-cache
    User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36

**Request Payload**
------WebKitFormBoundary10QktAWiD1GCsBKF
Content-Disposition: form-data; name="uploadFile"; filename="error.txt"
Content-Type: text/plain


------WebKitFormBoundary10QktAWiD1GCsBKF--

Solution

  • The problem was commons-upload pom dependency.

    I was using commons-upload for upload files that was working fine into local but its gave multipart error when pushed to Predix. So after removing it and respective bean configuration and then pushed to Predix it worked fine.