I’m trying to use jQuery Upload for the user to be able to upload files to the server. I’m testing it locally at the moment. I don’t get any error messages, but I don’t see any files getting uploaded to the upload folder either.
In a js file on client side:
Template.submitDesign.created = function() {
Uploader.init(this);
}
Template.submitDesign.rendered = function () {
Uploader.render.call(this);
};
Template.submitDesign.events({
'change #file': function(e) {
Uploader.startUpload.call(Template.instance(), e);
}
});
init.js on server:
Meteor.startup(function () {
// init items collection
if (Items.find().count() == 0) {
Items.insert({name: 'My Item', uploads: []});
}
UploadServer.init({
tmpDir: process.env.PWD + '/.uploads/tmp',
uploadDir: process.env.PWD + '/.uploads/',
checkCreateDirectories: true,
getDirectory: function(fileInfo, formData) {
if (formData && formData.directoryName != null) {
return formData.directoryName;
}
return "";
},
getFileName: function(fileInfo, formData) {
if (formData && formData.prefix != null) {
return formData.prefix + '_' + fileInfo.name;
}
return fileInfo.name;
},
finished: function(fileInfo, formData) {
if (formData && formData._id != null) {
Items.update({_id: formData._id}, { $push: { uploads: fileInfo }});
}
}
});
});
html:
<form id="submit" class="custom" method="POST" enctype="multipart/form-data">
<div class="row add-attachments">
<div class="columns text-right" >
<label><input id="file" type="file" name="file" multiple="true" data-form-data='{{ submitData }}'><span>+ Add Attachments</span></label>
</div>
</div>
<button class="final" type="submit">Submit</button>
</form>