change upload folder and putting the location of the image in the api - sails.js -



change upload folder and putting the location of the image in the api - sails.js -

i have client-side application register form send info sails.js based server. other basic info that's beingness send, have image upload uploads image ./tmp/uploads

here server side code(in controller):

upload: function (req, res) { req.file('avatar').upload({ dirname: 'uploads' }, function (err, uploadedfiles){ if (err) homecoming res.send(500, err); res.view({ items: uploadedfiles }); }); }

1) how alter folder files goes to? obiously dont want files saved in .tmp folder

2)how insert image location info api has beingness created? , speaking of image location, how access image file? usualy expected localhost:1337/.tmp/uploads/file.jpg work.

1) have set absolute path in prop 'dirname', example:

var path = '/var/www/app/uploads'; req.file('avatar').upload({ dirname: path }, function (err, uploadedfiles){

or can utilize relative path controller:

var path = __dirname + '/../uploads'; req.file('avatar').upload({ dirname: path }, function (err, uploadedfiles){

2) have access every model in controllers, suppose have image model, save location way:

image.update({id:1},{location: path + '/' + uploadedfiles[0].filename})

sails.js

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -