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
multipart/related stream body upload #758
Comments
+1 |
can you give me a code sample? |
This doesn't work for me :
|
what does this have to do with multipart? the code sample you just posed is a json object which, by default, we post as if you want multipart forms checkout the form documentation https://github.com/mikeal/request#forms |
var request = require('request');
var source = 'https://registry.npmjs.org/';
var target = 'http://requestb.in/x2qhewx2';
request({ url: source, qs: { test: 1 } }).pipe(request(target));
try {
request({
url: target,
qs: { test: 2 },
body: request(source)
}, function (error, response, body) {
console.log('this never happens because an error is thrown', error);
}).on('error', function (error) {
console.log('body stream on error:', error);
});
} catch (error) {
console.log('body stream thrown error:', error);
}
request({
url: target,
qs: { test: 3 },
multipart:[
{ body: 'test' },
{ body: request(source) }
]
}, function (error, response, body) {
console.log('this silently fails. error:', error);
}).on('error', function (error) {
console.log('multipart body stream on error:', error);
}); Result:
Network output: The test 1 works (except that with the piping it seems the source request headers & query string are also forwarded to the target request, ignoring the The test 2 doesn't work, as expected, but indicates the issue clearly: it throws an error. It's strange though that it throws the error even if we have a callback and an event listener on 'error' that can be used to notify the error. Usually the error is thrown only if there is no other way to notify the error (a callback or an error listener). Should I fill a new issue for that? The test 3 doesn't work, as expected, but silently fails: no error is thrown, no 'error' event is emitted, no error on the callback first argument. The HTTP request just contains an empty part:
It is clearly an issue that it silently fails; but we could to better than throwing an error: we could accept a stream as body, both in multipart and standard body |
+1 |
+1 for this. Need a way to specify the multipart/related body as a stream. |
@FredKSchott does this feature relate at all to the multipart form stuff you worked on? |
Yup, support for this has been added with the |
The initial issue is still here. The feature request for multipart stream support is partly implemented by the new However, the bug report of this issue is not fixed at all: if we put a stream object as body in |
@FredKSchott comments on my last remarks? Could someone re-open the issue? |
@triccardi-systran check out the docs, with the latest release it is possible to pass streams as multipart/related body |
Ah my bad @triccardi-systran, the notification must have gotten lost in the shuffle. |
Current
multipart
option for multipart/related requests only works with buffers or stringbody
.When setting
body
to a stream (like afs.createReadStream()
) it silently fails and sends an empty part.This would be a great addition to
request
to handle this.As we don't know the stream final size this forces the use of chunk encoding, but it's not an issue for me.
In the meantime we could have a real error when the
body
type is not supported.The text was updated successfully, but these errors were encountered: