fixed uploadPDF() Header problem
This commit is contained in:
parent
c9e97cefdc
commit
ebca4591fa
|
@ -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');
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
BIN
uploads/pdfs/snthsnthsnth_submission_1435630540895.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435630540895.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435631451599.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435631451599.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435631701333.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435631701333.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435632021223.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632021223.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435632187529.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632187529.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435631554812.pdf
Normal file
BIN
uploads/tmp/1435631554812.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435632257136.pdf
Normal file
BIN
uploads/tmp/1435632257136.pdf
Normal file
Binary file not shown.
Loading…
Reference in a new issue