I have looked around and looked at various tutorials on how to upload a file using node/express. I feel like I am doing something wrong on either the HTML or JQuery side. I am using the following link as a http://howtonode.org/really-simple-file-uploads.
However I am getting the error:
TypeError: Cannot read property 'fileUpload' of undefined at module.exports.fileCreate
Here is my code below:
uploadcontroller.js
fs.readFile(req.files.fileUpload.path, function (err, data) {
var newPath = __dirname + "/uploads/" + imgString;
fs.writeFile(newPath, data, function (err) {
});
});
html snippet
<div class="form-group">
<label for="fileUpload">Upload File</label>
<input type="file" name="fileUpload" id="fileUpload">
</div>
I am using the Sails framework (not sure if that makes difference)
Edit: Complete Form
<form role="form" class="uploadFileForm">
<div class="form-group">
<label for="fileTitleInput">Title</label>
<input type="text" name="formTitleInput" id="formTitleInput">
</div>
<div class="form-group">
<label for="fileDescriptionInput">Description</label>
<textarea class="form-control" rows="4" id="fileDescriptionInput"></textarea>
</div>
<div class="form-group">
<label for="fileUpload">Upload File</label>
<input type="file" name="fileUpload" id="fileUpload">
</div>
<button type="submit" class="btn btn-default" id="file-submit-btn">Publish to Web</button>
</form>