I've build site with admin panel with Sailsjs and deployed it on Heroku.
Then I've uploaded image with Skipper. When i try to:
fs.readdir "#{__dirname}/../../assets/images/Projects", (err, file)->
console.log file
I can see my file in folder.
But i can't get it with ajax or in img tag. Here is code to upload (also if you can help me to optimize this code, I would be very greatfull) :
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"
Aucun commentaire:
Enregistrer un commentaire