Creating package with multiple document binaries, uploading with superagent.
Monday, May 9, 2016 at 08:00amHi!
I have been trying to upload multiple documents with a post request to '/api/packages' (the sandbox) url and getting getting the error indicating the number of documents sent in the payload is different from what I attached,
Could have a look at the code and let me know, what I am missing?
var httpReq = require('superagent'); var _ = require('lodash'); var createPackageReq = httpReq .post(config.esignature.host + '/packages') .set('Content-type', 'multipart/form-data') .set('Accept', 'application/json') .set(SILANIS_AUTHORIZATION); //my API Key //req is the request passed on to this function from my UI _.keys(req.body.documents).forEach(function(docName) { documents.push({name: docName}); createPackageReq .attach(docName, req.body.documents[docName].result.path); }); var stringData = JSON.stringify({documents: documents}); createPackageReq .field('payload', stringData) ..end(function(err, resp) { if(err) { // console.log(resp.error); throw err; } if (resp.statusCode === 200) { // console.log(resp.body); res.send(resp.body); } else { res.sendStatus(resp.statusCode); } });and below is the error I am getting,
[Error: cannot POST /api/packages (400)] status: 400, text: '{ "entity":null, "messageKey":"error.validation.package.wrongNumberOfFiles", "technical":"Number of uploaded files does not match number of documents specified in package.", "packageId":null, "message":"Number of uploaded files does not match number of documents specified in package.", "code":400, "name":"Validation Error" }', method: 'POST', path: '/api/packages'Thanks, Vinay
Reply to: Creating package with multiple document binaries, uploading with superagent.
Monday, May 9, 2016 at 09:33amReply to: Creating package with multiple document binaries, uploading with superagent.
Monday, May 9, 2016 at 01:08pm