Downloaded file (image) from Sails.js (Node.js) but cannot get it from client. Heroku application
I created a site with admin panel with sails.js and deployed to Heroku.
Then I uploaded the skipper image. When I try:
fs.readdir "#{__dirname}/../../assets/images/Projects", (err, file)->
console.log file
I can see the file in the folder.
But i cant get it with ajax or in img tag. Here is the code to download (also, if you can help me optimize this code, I would really like it):
create: (req, res, next)->
project_id = req.param('id')
res.setTimeout(0)
if !project_id
res.set('Content-Type', 'text/html; charset=utf-8')
return res.badRequest('No id provided.')
images_name = []
files_counter = 0
fileName = (__newFileStream, cb)->
name = uuid.v4() + path.extname(__newFileStream.filename)
# Saving names in array to insert it database
images_name.push name
cb null, name
uploadFile = req.file('uploadFile')
uploadFile.upload {dirname: "#{__dirname}/../../assets/images/Projects", saveAs: fileName}, (err, files)->
return res.serverError(err) if err
if uploadFile.isNoop
res.set('Content-Type', 'text/html; charset=utf-8')
return res.badRequest('No images provided!')
for image,index in files
nImage = {}
# Inserting name from array to database
nImage.image = images_name[index]
nImage.project_id = project_id
ProjectImages.create nImage, (error, image) ->
if error
res.status 400
return res.json error
files_counter++
if files_counter == files.length
res.status 200
return res.send "Images upload done"
+3
source to share
No one has answered this question yet
Check out similar questions: