abao icon indicating copy to clipboard operation
abao copied to clipboard

multipart/form-data request not sending content-type header

Open kimor79 opened this issue 9 years ago • 7 comments

I'm trying to test a multipart/form-data endpoint but it seems as though the content-type header isn't being sent when I run abao.

Raml snippet:

/stuff:
  put:
    body:
      multipart/form-data:
        formParameters:
          name:
            description: The name of the stuff
            required: true
            type: string
            example: My_Stuff
          image:
            description: A picture of the stuff
            required: true
            type: file
    responses:
      201:
        body:
          application/json:

If I change multipart/form-data to application/json I can see the request getting further (but then fails because the required input isn't passed... as expected)

Thoughts?

Thanks Kimo

kimor79 avatar May 05 '15 23:05 kimor79

Abao send application/json in default as it only support json validation now. But you can let Abao sent other MIME type like multipart/form-data by writing a hookfile. You can find instructions of writing hookfile in README.

cybertk avatar May 06 '15 00:05 cybertk

Hi @cybertk: can you tell me how to add a file in a hook? I did something like this but it doesn't work:

test.request.headers['Content-Type'] = 'multipart/form-data; boundary=---------------------------1855940011132119363825021521';
test.request.body = '---------------------------1855940011132119363825021521\n' +
        'Content-Disposition: form-data; name="image"; filename="source2.png"\n' +
        'Content-Type: image/png\n\n' +
        fs.readFileSync('/tmp/image/source2.png') + '\n' +
        '---------------------------1855940011132119363825021521--\n';

any idea?

ferrylauda avatar Aug 27 '15 12:08 ferrylauda

I am sorry, abao does not support this now. It only support json payload

cybertk avatar Aug 27 '15 13:08 cybertk

@cybertk: thanks for the info. It might be a nice feature for abao :)

ferrylauda avatar Aug 27 '15 15:08 ferrylauda

:+1:

Logifire avatar Feb 02 '16 09:02 Logifire

yes , it should be important for us.

davidli2017 avatar Feb 22 '16 06:02 davidli2017

Is there a way to send multipart/form-data content in request.

If so how do I send it please refer to the below node js script for your reference:

var request = require("request");

var options = { method: 'POST', url: 'http://url/add_requester', headers: { authorization: 'token', 'content-type': 'multipart/form-data; boundary=---011000010111000001101001' }, formData: { name: 'test name', username: 'testuserjjf', email: '[email protected]', handphone_number: '+62345-23456789', nik: '' } };

Can formdata json above be included in hookfile, if so how ? my api accepts data in mutipart/form-data format as per wire shark trace.

sugh01 avatar Jul 12 '16 12:07 sugh01