Reputation: 4538
I'm driving a node.js/express.js app with curl. The curl command:
curl -X PUT -i -T LICENSE.txt localhost:9981/v1/test/bucket/some-object -s
errors, saying content-type should be present. Content-type of 'text/plain' does not work. In fact, the only content-type that works seems to be: Content-Type: multipart/form-data; boundary=---something
However! What should be the boundary, if I'm only putting some text file? The curl command hangs because, I assume, the boundary cannot be made up.
Now, this curl command works: curl localhost:9981/v1/test/container/some-object -X PUT -F "file=@/opt/nedge/README.md"
But this is not quite what I want, because I don't want to specify file=@
And the last piece of the question is, the node.js code that is being run. It is the example busboy, the first example from their github: https://github.com/piousbox/busboy
My question is: either how to specify the correct boundary with curl, or how to make busboy (or node.js streams overall) accept content-type other than multipart/form-data
.
Upvotes: 1
Views: 3004
Reputation: 106696
Busboy only processes multipart/form-data (generally when at least one of the fields is a file) or application/x-www-form-urlencoded requests (no files). If you need to process a 'text/plain' or other type of request, then just add your own middleware before your regular form processing middleware. Something like this perhaps:
// ....
app.use(function(req, res, next) {
if (!req.headers['content-type'])
return next(new Error('Bad request'));
if (req.headers['content-type'].indexOf('text/plain') === 0) {
// read from `req` here with req.read() or req.on('data', ...), etc.
} else
next();
});
// ....
Upvotes: 1