fixed uploadPDF() Header problem

This commit is contained in:
David Baldwynn 2015-06-29 19:45:25 -07:00
parent c9e97cefdc
commit ebca4591fa
10 changed files with 19 additions and 22 deletions

View file

@ -38,7 +38,7 @@ exports.create = function(req, res) {
/** /**
* Upload PDF * Upload PDF
*/ */
exports.uploadPDF = function(req, res, next) { exports.uploadPDF = function(req, res) {
var parser = new PDFParser(), var parser = new PDFParser(),
pdfFile = req.files.file; pdfFile = req.files.file;
@ -50,34 +50,33 @@ exports.uploadPDF = function(req, res, next) {
if (req.files) { if (req.files) {
if (pdfFile.size === 0) { if (pdfFile.size === 0) {
return next(new Error('Hey, first would you select a file?')); return res.status(400).send({
message: 'Hey, first would you select a file?'
});
} }
fs.exists(pdfFile.path, function(exists) { fs.exists(pdfFile.path, function(exists) {
if(exists) { if(exists) {
console.log('UPLOADING FILE \N\N'); // console.log('UPLOADING FILE \N\N');
res.end('Got your file!'); return res.status(200).send({
next(); message: 'Got your file!'
// return res.status(200); });
} else { } else {
res.end('DID NOT get your file!'); return res.status(400).send({
next(); message: 'Did NOT get your file!'
// return res.status(400); });
} }
}); });
} }
next(new Error('FILE NOT UPLOADED')); return res.status(400).send({
message: 'FILE NOT UPLOADED'
// return res.status(400); });
// res.json(pdfFile);
}; };
/** /**
* Show the current form * Show the current form
*/ */
exports.read = function(req, res) { exports.read = function(req, res) {
// console.log(req.form);
console.log(req.form.form_fields[7]);
res.json(req.form); res.json(req.form);
}; };
@ -112,7 +111,7 @@ exports.createSubmission = function(req, res) {
fdfData = pdfFiller.fillFdfTemplate(fdfTemplate, submission.form_fields, null); fdfData = pdfFiller.fillFdfTemplate(fdfTemplate, submission.form_fields, null);
submission.fdfData = fdfData; submission.fdfData = fdfData;
//Create new file //Create new file
// pdfFiller.fillForm( form.pdf.path, config.pdfUploadPath+form.title+'/'+form.title+'_'+Date.now()+'_submission.pdf', fdfData, function() { // pdfFiller.fillForm( form.pdf.path, config.pdfUploadPath+form.title+'/'+form.title+'_'+Date.now()+'_submission.pdf', fdfData, function() {
// console.log('\n\n\n fdfData'); // console.log('\n\n\n fdfData');

View file

@ -111,7 +111,6 @@ FormSchema.pre('save', function (next) {
} }
}); });
//Autogenerate FORM from PDF if 'isGenerated' flag is 'true' //Autogenerate FORM from PDF if 'isGenerated' flag is 'true'
FormSchema.pre('save', function (next) { FormSchema.pre('save', function (next) {
var field; var field;
@ -164,7 +163,6 @@ FormSchema.pre('save', function (next) {
//Throw error if we encounter form with invalid type //Throw error if we encounter form with invalid type
next(); next();
}); });
FormSchema.methods.convertToFDF = function (cb) { FormSchema.methods.convertToFDF = function (cb) {

View file

@ -97,14 +97,14 @@ FormSubmissionSchema.pre('save', function (next) {
pdfFiller.fillForm(_form.pdf.path, dest_path, this.fdfData, function(err){ pdfFiller.fillForm(_form.pdf.path, dest_path, this.fdfData, function(err){
console.log("fdfData: \n"); console.log('fdfData: \n');
console.log(that.fdfData); console.log(that.fdfData);
// console.log("_form.pdf.path: "+_form.pdf.path); // console.log('_form.pdf.path: '+_form.pdf.path);
// console.log("dest_path: "+dest_path); // console.log('dest_path: '+dest_path);
if(err) { if(err) {
console.log("\n err.message: "+err.message); console.log('\n err.message: '+err.message);
next( new Error(err.message) ); next( new Error(err.message) );
} }
console.log('Field data from Form: '+_form.title.trim()+' outputed to new PDF: '+dest_path); console.log('Field data from Form: '+_form.title.trim()+' outputed to new PDF: '+dest_path);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.