Multipart data (json +file)

Hello
I want to send HTTP post request that has json + file upload. Can I do it in one shot? Or I have to send json first and then attachment (file)?

Can someone please guide?

Search the forum for multipart.

Here is one such example : Form-data multipart-encoded request with pdf file attached into the body

`I have referred the page you have recommended. Can you please tell me whats going wrong?

[{"id":"a12f24af.f30b98","type":"function","z":"5b4e4e9f.708f4","name":"","func":"msg.headers = {\n 'content-type' : 'multipart/form-data'\n}\n\nmsg.payload = {\n file: {\n field: 'file',\n data: msg.payload.byteArray,\n type: 'binary',\n name: msg.payload.fname\n },\n formOptions: {\n ideaName: 'idea1',\n problemDescription:'problem1'\n }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":,"x":370,"y":340,"wires":[["412c3b14.67b054"]]}]

I am using fileinject which passes msg.payload to a function. My function looks like this

var fileData = msg.payload;
var msg1,msg2

var data={ "ideaName": "idea1",
"problemDescription":"test"};
msg.headers = {'Content-Type': 'multipart/form-data'};

msg1 = {payload: {JSONString: JSON.stringify(data)}} ;

msg2={payload:{

'image' : {
    'value': fileData,
    'options': {
        'filename': 'mytest.txt'
    }
}

}

}

return[msg,[msg1,msg2]];

But this sends only file paylod to HTTP request.

Any guidance?

That won't be multipart.

Check this other thread (that I found by searching multipart)...

thanks!
[{"id":"5b4e4e9f.708f4","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"9c0b2081.b1ac6","type":"function","z":"5b4e4e9f.708f4","name":"Format the header and payload","func":"msg.headers = {\n "Content-Type": "multipart/form-data; boundary=------------------------d74496d66958873e"\n}\n\nmsg.payload = '--------------------------d74496d66958873e\r\n'+\n'Content-Disposition: form-data; name="ideaName"\r\n'+\n'\r\n'+\n'idea1\r\n'+\n'--------------------------d74496d66958873e\r\n'+\n'Content-Disposition: form-data; name="problemDescription"\r\n'+\n'\r\n'+\n'test\r\n'+\n'--------------------------d74496d66958873e\r\n'+\n'Content-Disposition: form-data; name="file"; filename="/C:/Users/Yogini/Downloads/VAST_2021_Holiday List (1).pdf"\r\n'+\n'Content-Type: text/plain\r\n'+\n'\r\n'+\nmsg.payload+'\r\n'+\n'--------------------------d74496d66958873e--\r\n';\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":,"x":310,"y":540,"wires":[["85c748e8.2d1f88"]]},{"id":"85c748e8.2d1f88","type":"http request","z":"5b4e4e9f.708f4","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://prod-102.westus.logic.azure.com:443/workflows/13a1c2517dea4c10b56508b83069102a/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=pK7xXXMjndVz0Kfdp4glDimhKgFscAhZBqlvSGKd9K4","tls":"","persist":false,"proxy":"","authType":"","x":550,"y":540,"wires":[["a4810d7a.f652a"]]},{"id":"a4810d7a.f652a","type":"debug","z":"5b4e4e9f.708f4","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":520,"wires":[]},{"id":"ed2d4050.7a30e","type":"fileinject","z":"5b4e4e9f.708f4","name":"","x":170,"y":380,"wires":[["9c0b2081.b1ac6"]]}]

I see file payload but dont see form data

{"payload":"","filename":"mytest.txt","mimetype":"text/plain","_msgid":"2de3f8e8.177ba8","headers":{"cache-control":"no-cache","pragma":"no-cache","expires":"-1","x-ms-workflow-run-id":"08585758519470315704503619175CU102","x-ms-correlation-id":"8686c4a5-e433-4a4d-917c-aa0d25c226b1","x-ms-client-tracking-id":"08585758519470315704503619175CU102","x-ms-trigger-history-name":"08585758519470315704503619175CU102","x-ms-execution-location":"westus","x-ms-workflow-system-id":"/locations/westus/scaleunits/prod-102/workflows/13a1c2517dea4c10b56508b83069102a","x-ms-workflow-id":"13a1c2517dea4c10b56508b83069102a","x-ms-workflow-version":"08585776812655828111","x-ms-workflow-name":"d74a2bd5-7740-2aba-a189-dbf7642adc50","x-ms-tracking-id":"8686c4a5-e433-4a4d-917c-aa0d25c226b1","x-ms-ratelimit-burst-remaining-workflow-writes":"2998","x-ms-ratelimit-remaining-workflow-download-contentsize":"214748160","x-ms-ratelimit-remaining-workflow-upload-contentsize":"214747200","x-ms-ratelimit-time-remaining-directapirequests":"19999867","x-ms-request-id":"westus:8686c4a5-e433-4a4d-917c-aa0d25c226b1","strict-transport-security":"max-age=31536000; includeSubDomains","date":"Thu, 08 Jul 2021 14:35:38 GMT","connection":"close","content-length":"0","x-node-red-request-node":"30b94f73"},"statusCode":202,"responseUrl":"https://prod-102.westus.logic.azure.com:443/workflows/13a1c2517dea4c10b56508b83069102a/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=pK7xXXMjndVz0Kfdp4glDimhKgFscAhZBqlvSGKd9K4","redirectList":}

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.