0

The Issue: Resulting uploaded json file contains the curl boundary information.

Requirement: file posted should be exactly the file uploaded on the server side.

Stack: Busboy (https://github.com/mscdex/busboy), Node, Express, cURL

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));

app.post('/foo', function(req, res) {
  // some logic
  
  if (req.busboy) {
    req.pipe(req.busboy);
    file.pipe(fs.createWriteStream(fpath));
    fstream.on('close', function() {
      deferred.resolve(fpath);
    });

    
    //more logic
  }
});

curl http://localhost:3000/foo -v -X POST -F "file=@file.json"

Update:

I went with a module called multer

var multer = require('multer');
var upload = multer({ dest: 'uploads/' });

router.post('/upload', upload.single('file'), function (req, res) {
  if (!req.file) {
    throw 'No file 
    }
    
    res.send('success. file is at: %s', req.file.path);
});

/*
  works with curl request like so:
  
  curl http://localhost:3000/upload \
  -X POST \
  -F "file=@npm-shrinkwrap.json"
*/
Kevin Friedheim
  • 394
  • 3
  • 15
  • So why not just use `curl http://localhost:3000/foo -d @file.json` ? – Daniel Stenberg Jun 30 '17 at 21:28
  • hmmm so I wouldn't use something like `busboy` to consume the incoming multipart data - I'd just stream the incoming file as data and write it out to a file... ya okay I'll give that a go. – Kevin Friedheim Jun 30 '17 at 23:00
  • soooooo I'm still very stuck on this - this should be possible right?? Like using curl to hit my post works -- siiiigh I know I could just do the dumb thing and send the large file contents as data - but that's not what I want since there's a limit... – Kevin Friedheim Jul 01 '17 at 01:37
  • Update: I never actually figured out how to get this working with `busboy-connect` but I was able to get things working with [multer](https://github.com/expressjs/multer) - I'd still like to know if this was maybe a defect in `busboy-connect` or just something dumb that I was doing - but its less pressing now I guess. – Kevin Friedheim Jul 01 '17 at 17:12

0 Answers0