Forum Discussion

CXin's avatar
CXin
Frequent Contributor
14 years ago

how to post with attachment in REST

Hi,

I have problem with posting with attachment in REST.
I saw a doc for this http://www.soapui.org/SOAP-and-WSDL/add ... ments.html
But it is only for soap and I don't see any properties related to MTOM.

Our REST service doesn't have a WADL by the way.

7 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    In the Request window, you should have an Attachments tab near the bottom of the request part. If you open this tab, you should be able to add file attachments to your request. Make sure to select the media type: "multipart/form-data" in the dropdown menu for the request, and that the HTTP Method is set to POST.

    Regards,
    Dain
    eviware.com
  • CXin's avatar
    CXin
    Frequent Contributor
    I saw a lot of garbage char, how to set the encoding?

    POST http://www.ecg-api.kijiji.ca.staging.in ... i/pictures HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: multipart/form-data; boundary="----=_Part_3_16632831.1294304305637"
    MIME-Version: 1.0
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: www.ecg-api.kijiji.ca.staging.intern.qa-kijiji.com
    Content-Length: 45849


    ------=_Part_3_16632831.1294304305637
    Content-Type: application/octet-stream; name="API output list.xls"
    Content-Transfer-Encoding: binary
    Content-Disposition: form-data; name="API output list.xls"; filename="API output list.xls"

    ÐÏ à¡± á
  • CXin's avatar
    CXin
    Frequent Contributor
    By the way, what's the different for curl -F @file=bla.jpg to add the file in the attachment ?

    in the raw part, I see the attached image is encoded into a lot of chars but it is not actually accepted by my REST service.

    Can any of you give me a hand on any of the question I raised?

    It seems none of them is solved...
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    I cannot tell you why your server is rejecting the file, since I do not know what it is expecting to receive. You are not using a known standard, and neither I nor the soapUI software will be able to tell you how to create the request you are after without knowing what it is you actually want to send. The curl command you have given (I assume you mean "curl -F file=@bla.jpg") sends a file much in the same was that soapUI does when the content type is correctly set as multipart/form-data. Since this is form data we're talking about, each form field has both a name and a value. I'm just guessing here, but perhaps your server isn't accepting the file because it is expecting it to have a different form field name? The curl command you're using (again, assuming "curl -F file=@bla.jpg") sets the form field name to "file". By default soapUI sets this name to whatever the file name is, but it's easily changed by changing the "ContentID" field for the attachment in soapUI. If this isn't working, I can't help you without an exact specification of what your server actually accepts.

    Regards,
    Dain
    eviware.com
  • CXin's avatar
    CXin
    Frequent Contributor
    Hi,

    thanks for the reply!

    But how can I change the contentID?
    I think it is read only?
  • CXin's avatar
    CXin
    Frequent Contributor
    Hi,

    I've figured out the solution to this issue.
    Thank you so much.
    • jopjop's avatar
      jopjop
      Frequent Visitor

      Hi CXin