1

I'm playing with a restapi which give me a link to create an article. The form accepts article name, comments and images. I'm trying to use plupload to upload the images. It's working fine however due to the fact plupload makes a post per image I end up with i.e three articles if uploading three images.

I can manage to send each image with additional params, which in this case are "article name" and "comments". However I want one article with the three images and one article name and comment. Not three separate images with the same "article name" and "comment".

I hope my question is clear and someone has dealt with a similar situation and can point out some solutions. I want to create one mongo doc not three ;)

Thanks.

Stennie
  • 63,885
  • 14
  • 149
  • 175
fpena06
  • 2,246
  • 3
  • 20
  • 28
  • As far as I know, you can't do that with plupload. Does your API handle updates ? If so, adding the different files as updates to the primarily created doc might be a good option. – jbl Jan 23 '14 at 13:04
  • Yes here is my code. `exports.update = function(req, res){ var article = req.article article = extend(article, req.body) article.uploadAndSave(req.files.image, function(err) { if (!err) { return res.redirect('/articles/' + article._id) } res.render('articles/edit', { title: 'Edit Article', article: article, errors: err.errors }) }) }` how can I update it so that if the article doesn't exist it would create one and update there after? – fpena06 Jan 23 '14 at 22:26
  • Sorry, not proficient enough in server-side js. You should perform an ajax call on BeforeUpload (and defer file upload) just to create the article, then upon receiving the Id of the created article, add this Id parameter to the resumed file uploading, targetting the update method. As to adding parameters, see http://stackoverflow.com/q/13367897/1236044 – jbl Jan 25 '14 at 21:19

0 Answers0