3

I've built a site with admin panel with sails.js 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"
Travis Webb
  • 14,688
  • 7
  • 55
  • 109
Dionid
  • 31
  • 3
  • What path are you setting in the ```src``` attribute of your ```img``` tag? – Ryan Apr 19 '15 at 01:44
  • , but images that I've loaded then deploying ( "$ git push heroku master") displaying properly – Dionid Apr 19 '15 at 11:05
  • Hrm. I'd recommend using an absolute path to your image, i.e. ``````, but I doubt that's the problem here. Can you set Sails' log level to 'silly' and post the log of what happens during the upload? Should include ```verbose: Grunt :: >> File "assets/images/image_name.jpg" added.``` along with some other stuff. – Ryan Apr 23 '15 at 06:39
  • Oh, one other thing, if you put the link to the uploaded image in a new browser window, do you get a Sails 404 page, or something else? – Ryan Apr 23 '15 at 06:41

0 Answers0