Closed jebcode closed 8 years ago
Very vague description, sorry ;( Where do you actually insert something to the Uplaod collection?
That's a good question :) I'm using the built in dropzone in my template, so I'm not sure where the insert into Uploads collection actually happens. Below was my workaround in the finished function with a setTimeout of 1s - not sure why that was necessary. I know it's ugly, but that's all I could figure out at the time!
Below is on server side only:
Meteor.startup(function () {
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) {
Meteor.setTimeout(function () {
var upload = Uploads.findOne({path: fileInfo.path});
MyCollection.update({_id: formData._id}, {$push: {uploads: upload._id}});
}, 1000);
},
mimeTypes: {
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"png": "image/png",
"gif": "image/gif",
}
});
});
Figured it out - thanks for asking that question!
On the client side I just did:
Meteor.startup(function () { Uploader.finished = function (index, fileInfo, templateContext) { var uploadId = Uploads.insert(fileInfo); MyCollection.update({_id: templateContext.data.formData._id}, {$push: {uploads: uploadId}}); } });
finished: function (fileInfo, formData) { console.log(Uploads.find({}).count()) //this is not including the new upload in the count //would like to get the _id of the upload here },