0

I am trying to upload multiple files in a server using http builder-groovy.The below code doesn't works.Getting an error " Request entity is too large" .I have imported all the packages and defined all the variables.

Is there any alternative for this using restclient-groovy?

can anyone give the reason?

thanks in advance.

def file = new File("resources/IMG.JPG")
def file1 = new File("resources/aa.json")

http = new HTTPBuilder( url )

http.request (POST, JSON) { multipartRequest ->

      uri.path = '/server/upload'
      uri.query = [param1:value, param2:value, param3:value, param4:value]

      requestContentType = 'multipart/form-data'

      MultipartEntity mpe = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
      mpe.addPart( "jpeg", new FileBody(( File ) file , 'image/jpeg' ))
      mpe.addPart( "json", new FileBody(( File ) file1 , 'application/json' ))

      multipartRequest.setEntity(mpe)

      response.success = { resp, json->
          println "POST response status: ${resp.statusLine}"
          println "Query response: ${json}"
      }

      response.failure = {  resp ->
          println "POST response statusline: ${resp.statusLine}"
      }
}
Gergely Toth
  • 6,638
  • 2
  • 38
  • 40
sailakshmi
  • 45
  • 1
  • 2
  • 6

2 Answers2

1

You could actually use RestAssured framework to form multipart requests with ease.

Below is an example,

@Test
public void multiExample()
{
    given().
        multiPart("image", new File("resources/a.jpg"), "image/jpeg").
        multiPart("lgdata", new File("resources/myfile.json"), "application/json").
    expect().
        body("result", is("OK")).
    when().
        post(url);

}
0

as per Wikipedia:

413 Request Entity Too Large

The request is larger than the server is willing or able to process.

check your server

Community
  • 1
  • 1
injecteer
  • 20,038
  • 4
  • 45
  • 89