'/:id/photos', auth, (next)->
    if not 'multipart/*'
        @status = 400
        return yield next

    album = yield Album.findById
    if not album
        @status = 404
        return yield next

    photos = []
    parts = parse this,
        autoFields: true
    while part = yield parts
        # There is transaction problem to fix
        hashStream = new PassStream
        writeSream = new PassStream
        part.pipe hashStream
        part.pipe writeSream

        photo = new Photo
            title: part.fieldname
            album: album

        base = hashids.encodeHex photo._id
        ext = _.last part.filename.split '.'
        filename = path.join 'photos', "#{base}.#{ext}"
        filepath = path.join config.uploadDir, filename

        ret = [
            genHash hashStream
            cp writeSream, filepath
        hash = (yield ret)[0]

        photo.file = filename
        photo.hash = hash

            photo = yield
        catch e
            console.log 'errored'
            yield fs.unlink path.join config.uploadDir, photo.file
            console.log 'remove: ', photo.file
            for p in photos
                yield Photo.findByIdAndRemove p._id
                yield fs.unlink path.join config.uploadDir, p.file
                console.log 'rollback and remove: ', p.title, p.file
            throw e
        photos.push photo

    @body = photos
    yield next