I have an Express / Node application that is deployed on a Heroku instance. The application has a POST api point that expects a .json file, reads data, and populates the application with JSON data. Below is the code that processes the POST request:
router.route('/data') .post(function (req, res) { return DataUtils.storeData(req, res); }); Utils.storeData = function (req, res) { req.pipe(req.busboy); req.busboy.on('file', function (fieldname, file, filename) { file.on('data', function(data) { var data; try { data = JSON.parse('' + data);
When we try to execute the query using the curl command below:
curl -H "Content-Length: 5567" -F file=@sample _data / sample_json.json http: // [heroku-instance] / api / data
The server sometimes works fine and loads data, and at other times it generates an "Unexpected input end" error. It seems that the buffer method used does not read all the data for some reason. When registering data.length in the above code (like JSON) it seems that the request is interrupted whenever the data length is less than expected. Is there something wrong with the way I read in the JSON file above? Thanks -
source share