     @_callback table_name, req, action, opts
   _post:(table_name,action,name,params={},opts={})=>
     params.socket_id = window.socket_id if window.socket_id
-    req  = @$http.post name, params
+    if has_attached_file(params)
+      form_data = form_object_to_form_data(params)
+      req = @$http
+        method: 'POST'
+        url: name
+        data: form_data
+        transformRequest: angular.identity
+        headers:
+          'Content-Type': undefined
+    else
+      req  = @$http.post name, params
     @_callback table_name, req, action, opts
   _put:(table_name,action,name,params,opts={})=>
     params.socket_id = window.socket_id if window.socket_id
-    req  = @$http.put name, params
+    if has_attached_file(params)
+      form_data = form_object_to_form_data(params)
+      req = @$http
+        method: 'PUT'
+        url: name
+        data: form_data
+        transformRequest: angular.identity
+        headers:
+          'Content-Type': undefined
+    else
+      req  = @$http.put name, params
     @_callback table_name, req, action, opts
   _delete:(table_name,action,name,params={},opts={})=>
     params.socket_id = window.socket_id if window.socket_id

# (c) 2013 http://monsterboxpro.com
# License: MIT
#

class window.ApiBase
  _get:(table_name,action,name,params={},opts={})=>

  constructor:(@$rootScope,@$http)->
    _.each @resources, (options, table_name) =>
      @[table_name] =
        index   : (params,opts)=>       @_get    table_name, 'index'  , @path(table_name)       , params, opts
        new     : (params,opts)=>       @_get    table_name, 'new'    , @path(table_name,'new') , params, opts
        create  : (params,opts)=>       @_post   table_name, 'create' , @path(table_name)       , params, opts
        show    : (model,params,opts)=> @_get    table_name, 'show'   , @path(table_name,@_extract_id(model))        , params, opts
        edit    : (model,params,opts)=> @_get    table_name, 'edit'   , @path(table_name,@_extract_id(model),'edit') , params, opts
        update  : (model,params,opts)=> @_put    table_name, 'update' , @path(table_name,@_extract_id(model))        , params, opts
        destroy : (model,params,opts)=> @_delete table_name, 'destroy', @path(table_name,@_extract_id(model))        , params, opts
      _.each options.collection, (method, action) =>
        name = @path table_name, action
        fun = switch method
