I want to upload a file in my app.js server , which should pipe that file to a crossdomain server like my upload.js server.
The full code can be found under the foll
I had a similar problem but I wanted to stream the file directly to the remote server instead of saving it locally first. Here's my modifications to get streaming to work:
app.post('/upload', function(request, response, next) {
var form = new multiparty.Form();
form.on('part', function(formPart) {
var contentType = formPart.headers['content-type'];
var formData = {
file: {
value: formPart,
options: {
filename: formPart.filename,
contentType: contentType,
knownLength: formPart.byteCount
}
}
};
requestJs.post({
url: 'http://localhost:4000/upload',
formData: formData,
// These may or may not be necessary for your server:
preambleCRLF: true,
postambleCRLF: true
});
});
form.on('error', function(error) {
next(error);
});
form.on('close', function() {
response.send('received upload');
});
form.parse(request);
});