0

I am trying to send a request with content-type multipart/mixed

and simply print the request in my controller with the line println params

However, I keep getting an error: the request was rejected because no multipart boundary was found

I'm not sure whether this is a problem in grails or my request is messed up. I am using RESTConsole and setting the content-type to multipart/mixed and sending the following as RAW Body:

--boundary42 
Content-Type: text/plain; charset=us-ascii 

...plain text version of message goes here.... 

--boundary42 
Content-Type: text/richtext 

.... richtext version of same message goes here ... 
--boundary42 
Anthony
  • 33,838
  • 42
  • 169
  • 278

1 Answers1

1

multipart/mixed content-type is meant for a text/plain request with an attachment. Do you have an attachment in the request? If you do not send an attachment to the request then it will complain about multipart boundary.

Try to add an attachment (say a dummy file to the request in REST Console), you should see it working.

This content-type is mainly used for email contents [SMTP]. Abiding by the boundary, the text/plain content will be transformed to a message body. You can get the message body as HttpServletRequest.getInputStream

dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • If I send an attachment then the error goes away but now `println params` is not printing the `text/plain` sent along with the attachment. – Anthony May 16 '13 at 02:42
  • It works for me if I have, for example, `firstName=John&lastName=Doe` (query parameter string)set in the raw request body. Refer [this answer](http://stackoverflow.com/a/16572441/2051952) as an example. – dmahapatro May 16 '13 at 02:46
  • Unfortunately, I don't see the params printed if I do that. Please take a look at this screenshot: http://postimg.org/image/ln8exg0d3/ (note that I have query strings and an attachment) With that screen shot what I see printed in my console is: `params: [FIPS.png:org.springframework.web.multipart.commons.CommonsMultipartFile@6381db12, FIPS:[png:org.springframework.web.multipart.commons.CommonsMultipartFile@6381db12], action:[POST:save, GET:show, DELETE:delete, PUT:update], controller:mycontroller]` – Anthony May 16 '13 at 03:01
  • Oops small mix up, when content-type is `multipart/mixed`, request parameters are not required in the body, you can use the query string while POST. Use `Request Parameters` section in REST Console. – dmahapatro May 16 '13 at 03:32
  • Thanks. that will work. Request Parameters are being seen by the controller. So this way (upload the file and send query strings) will the file upload go in the request body? I'm trying to somehow mimic how dropbox api works, I asked a separate question as well http://stackoverflow.com/questions/16578475/what-content-type-does-dropbox-file-put-api-uses-and-how-to-mimic-it Thanks for help – Anthony May 16 '13 at 11:03
  • Saw your new question. Wanted to answer it but was half sleep that time.:) if you want get files and params in controller then Yes you can use the above approach, but in the new question you wanted the file to be sent as raw request body, that has to be handled a lot differently and lengthily. Spare me some time I will try to answer it appropriately. FYI, You need to use content-type multipart/form-data for Dropbox type service. – dmahapatro May 16 '13 at 11:10
  • Yes you can access the file in controller here as request.getFile(filename). – dmahapatro May 16 '13 at 11:30
  • Thanks @dmahapatro ! I'll wait for your answer there. I'm fine with using multipart/form-data as well. Thanks again! – Anthony May 16 '13 at 13:48