Wednesday 15 August 2018

How to associate uploaded image to existing asset?

Hi,I am developing my first app so bare with me.. I have a post route to upload images to my server. I would like the image to be attached to a particular asset. The asset already exist, I just want to update the record with the file name so I later can fetch the image for that asset.I am unsure how I should do this. The example code below is how I have tried to solve it so far and it does not actually work properly, i get errors in chrome console, complaining about mime type... What I am trying to do is send image to server and then update the record of asset id with the filename. But then I am doing both a post and put request (kind of) in the same route. What would be a good example dealing with it? The asset already exist so its an update on the asset but a new post request for the image. Does anyone have a recommendation?router.post('/:id', function (req, res) {upload(req, res, function (err) {if (err) {res.render('../views/pages/map', {msg: err});} else {if(req.file == undefined){res.render('../views/pages/map', {msg: 'Error: No File Selected'});} else {queries.updateImgName(req.params.id, req.file.filename).then(function() {res.render('../views/pages/map', {msg: 'File Uploaded!',file: \uploads/${req.file.filename}` }); //need error handling here if db was not updated }) } } }); });`

Submitted August 15, 2018 at 06:56PM by geoholic

No comments:

Post a Comment