-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 with JSON #455
Comments
No one? |
Actually, I don't understand the description quite well, but code below may be helpful for you. backend data resolve first. var express = require('express');
var multer = require('multer');
var app = express();
app.post('/', multer({
inMemory: true,
includeEmptyFields: true
}), function(req, res) {
/*
req.files contains file information
req.body contains other non-file information
*/
res.json(req.body);
});
app.listen(1337); superagent with multipart var request = require('superagent');
var should = require('should');
describe('superagent', function () {
it('with multi part', function (done) {
request
.post('http://localhost:1337')
.field('name', 'born')
.field('age', 23)
.attach('package', 'package.json')
.attach('index', 'index.js')
.end(function(res) {
try {
res.body.should.eql({
"name": "born",
"age": "23"
});
done();
} catch (err) {
done(err);
}
});
});
}); In theory, supertagent support both |
Okay two things, Is Can attach accept a file stream or a blob of text isntead of reading from a filename? |
It appears this was not answered Heres what I have found if it helps anyone
In other words passing a blob or a readableStream seems to be fine. If you want to pass a content type, you must provide a exstension that will qualify as the type you want. This seems straightforward however it is not in all cases since if you want to send a file as |
I'm using superagent with React and Rails and trying to compose a multipart request for the backend. Is there a way to add a JS object to the request without adding it field by field? For instance, I would like to have
But
Thank you in advance! |
You have to add fields one by one. |
The fields get converted to strings and fail validation. |
life saver |
Hi,
Can you please let me know how to attach a file and send the rest of the data as JSON? I've tried using req.part() but it has been deprecated.
Thanks.
The text was updated successfully, but these errors were encountered: