Skip to content

Instantly share code, notes, and snippets.

@chrisgfortes
Last active October 3, 2018 14:39
Show Gist options
  • Save chrisgfortes/6674a0d440756abeb0d8086f204317f1 to your computer and use it in GitHub Desktop.
Save chrisgfortes/6674a0d440756abeb0d8086f204317f1 to your computer and use it in GitHub Desktop.
Chakram send multipart/form-data file in post request
var chakram = require('chakram'),
expect = chakram.expect,
fs = require('fs'),
path = require("path");
describe("Chakram", function() {
it("Upload", function () {
var file = path.resolve(__dirname, './limites.txt');
var config = {
'formData': {
'file': fs.createReadStream(file),
},
'headers': {
'token': '54545d4f5d4f5d4f5d4f5',
'Content-Type': 'multipart/form-data'
}
}
return chakram
.post("https://pathUrl/endpoint/upload", undefined, config)
.then(function(res){
console.log(res.body);
expect(res).to.have.status(200);
});
});
});
@AnishVohra
Copy link

Hi Chris,

I have tried the same code snippet in my code and I am getting error code 500, Internal Processing Error.

My code snippet:
var file_path = 'IPSS_Test_Automation/features/test_data/IPDC327'
var file = path.resolve(file_path, './10Recs.json');
var config = {
'formData': {
'bulk-upload-file': fs.createReadStream(file),
},
'headers': {
'Content-Type': 'multipart/form-data'
}
}
requestParameters = config;

resObj = commonUtils.postReuestWithParameter(getApiURL,undefined,requestParameters);

Can you please let me know if I am doing something wrong.

The same file and POST request is working when doing from Postman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment