 async = require 'async'
 fs = require 'fs'
 thumbHelpers = require '../helpers/thumb'
+log = require('printit')
+    date: true
+    prefix: "file"
 
 onThumbCreation = require('../helpers/initializer').onThumbCreation
 fileByPage = 5 * 12

        binary       : file.binary

    Photo.create photo, (err, photo) ->
        return next err if err

        if photo.binary?.thumb? and photo.binary.screen?
            res.status(201).send photo

            # Add content thumb or screen if necessary
            rawFile = "/tmp/#{photo.id}"
            download res, file, rawFile, (err) ->
                if err?
                    log.error "Error downloading photo from file #{file.id}"
                    log.raw err
                    fs.unlink rawfile ->
                        return next err
                else
                    if not photo.binary.thumb?
                        thumbHelpers.resize rawFile, photo, 'thumb', (err) ->
                            if err?
                                log.error "Error resizing thumb #{photo.id}"
                                log.raw err
                                fs.unlink rawfile ->
                                    return next err
                            else
                                thumbHelpers.resize rawFile, photo, 'screen', (err) ->
                                    if err?
                                        log.error "Error resizing screen #{photo.id}"
                                        log.raw err
                                    fs.unlink rawFile, ->
                                        res.status(201).send photo
                    else if not photo.binary.screen?
                        thumbHelpers.resize rawFile, photo, 'screen', (err) ->
                            if err?
                                log.error "Error resizing screen #{photo.id}"
                                log.raw err
                            fs.unlink rawFile, ->
                                res.status(201).send photo
