 # create a FormData object with photo.file and photo.thumb
 # save the model with these files
 upload = (photo, next) ->
-
     formdata = new FormData()
     formdata.append 'raw', photo.file
     formdata.append 'thumb', photo.thumb, "thumb_#{photo.file.name}"


# width and height of generated thumbs
MAX_WIDTH = MAX_HEIGHT = 100

# read the file from photo.file using a FileReader
# create photo.img : an Image
# next : callback when the file have been read

readFile = (photo, next) ->
    reader = new FileReader()
    photo.img = new Image()
    reader.readAsDataURL photo.file
    reader.onloadend = =>
        photo.file_du = reader.result
        photo.img.src = reader.result
        photo.img.onload = ->
            next()

    canvas.height = MAX_HEIGHT
    ctx = canvas.getContext '2d'
    ctx.drawImage photo.img, 0, 0, newWidth, newHeight
    photo.thumb_du = canvas.toDataURL photo.file.type

    # let the view update itself
    photo.set 'thumbsrc', photo.thumb_du

    next()

