New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to pass in an object to formData #1495
Comments
This works for now ... var opts = {
url: 'my_service',
method: 'POST',
auth: { user: 'username', password: 'password' },
json: true,
formData: {
front: fs.createReadStream(file),
'to[name]': 'joe bob',
'to[address_1]': '123 main st'
}
}; |
That is the correct way to handle this, as the library |
Hey there just tried to do the same thing, |
I don't think that there is a standard way to handle object parameters outlined in the spec, although the |
how about this situation
|
The flattenJSON works great for me too, thanks @kengz ! |
This Options structure worked for me for POST request
|
You can checkout q-flat for converting nested objects to valid form data objects. |
What about arrays of arrays? It expects something like:
So I try to send the following:
But it's not working. Any idea? |
This really not intuitive -- is there a reason why this doesn't work? I encountered the same issue.
The error is "TypeError: source.on is not a function" I searched for hours to find this was the reason D: |
The |
This does work, but if you pass a JSON into the formData, you shoud var fs = require('fs');
var request = require('request');
var file = './test/assets/test.pdf';
var jsonData = {
name: 'joe bob',
address_1: '123 main st',
...
}
var opts = {
url: 'my_service',
method: 'POST',
auth: { user: 'username', password: 'password' },
json: true,
formData: {
front: fs.createReadStream(file),
to: {
value : JSON.stringify(jsonData),
options : {
contentType: 'application/json'
}
}
}
};
request(opts, function(err, resp, body) {
console.log(err, body);
}); |
It seems that whenever I add an object (such as the
to
object below) to formData, I get an error. If I remove theto
object or change it to a string, I no longer get an error.Why is this?
Error:
The text was updated successfully, but these errors were encountered: