   return _id
 
 insert_image_save_func = (template, coll_name, my_id, field_name) ->
+  payload = template.payload_var.get()
+  if !payload?
+    return
+
+  console.log "uploading payload",payload
+
   fb = template.$("#insert_image")[0]
   upload_files = fb.files
   # FIXME: assert size(upload_files)<=1

      scale = max_height/opts.full_image.height
      actual_width = opts.full_image.width*scale

    thumb = getThumbnail(opts.full_image, scale)
    payload.thumb_canvas = thumb

    div = template.find("#preview")
    $(div).empty()
    div.appendChild(thumb)
  template.payload.set( payload )
  template.upload_ready.set( true )

handle_files = (fileList, template) ->

  canvas.getContext('2d').drawImage original, 0, 0, canvas.width, canvas.height
  canvas

get_blob = ( canvas, type, quality ) ->
  binStr = atob( canvas.toDataURL(type, quality).split(',')[1] )
  len = binStr.length
  arr = new Uint8Array(len)

  i = 0
  while i < len
    arr[i] = binStr.charCodeAt(i)
    i++

  result = new Blob( [arr], {type: type || 'image/png'} )
  return result

handle_file_step_two = ( chosen_file, template, opts ) ->
  # FIXME: disable upload button until this processing is complete?
  payload = {}
  payload.original_file = chosen_file
  if opts.full_image?

    if opts.preserve_full_image
      canvas = document.createElement('canvas')
      canvas.width = opts.full_image.width
      canvas.height = opts.full_image.height

      ctx = canvas.getContext('2d')
      ctx.drawImage(opts.full_image, 0, 0, canvas.width, canvas.height)
      console.log "canvas.toBlob",canvas.toBlob
      payload.full_image_blob = get_blob( canvas, "image/jpeg", 0.8)

    max_width = 150 # from .no-thumb-item width
    max_height = 200 # from .no-thumb-item height
