title: Uploading an image from Android (with Android Asynchronous Http Client) to rails server (with paperclip)
body: <p>I'm trying to upload an image file via http post method from android device to rails server.
  But posting an image is not working. More specifically, the post parameter (including image file) doesn't seem to be sent correctly.</p>
  
  <p>I'm using Android Asynchronous Http Client (http://loopj.com/android-async-http/) to post an image from android, and the code for posting image is like this.</p>
  
  <pre><code>public static void postImage(){
      RequestParams params = new RequestParams();
      params.put("picture[name]","MyPictureName");
      params.put("picture[image]",File(Environment.getExternalStorageDirectory().getPath() + "/Pictures/CameraApp/test.jpg"));
      AsyncHttpClient client = new AsyncHttpClient();
      client.post("http://x.x.x.x:3000/pictures/", params, new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(String response) {
              Log.w("async", "success!!!!");
          }                                                                                                                                                                     
      }); 
  }   
  </code></pre>
  
  <p>As for rails paperclip application, I simply used scaffold and generated model named "pictures" and added paperclip attached file on it. Model and controller (which receives the request) is like below.</p>
  
  <p>model</p>
  
  <pre><code>class Picture &lt; ActiveRecord::Base                                                                                                                                            
    attr_accessible :name, :image
    has_attached_file :image,
                      :styles =&gt; { :original =&gt; "480x480&gt;", :thumbnail =&gt; "100x100&gt;" },
                      :path =&gt; ':rails_root/public/system/pictures/image/:id_partition/:style_:filename'
  end
  </code></pre>
  
  <p>controller</p>
  
  <pre><code># POST /pictures                                                                                                                                                              
  # POST /pictures.json
  def create
    @picture = Picture.new(params[:picture])
  
    respond_to do |format|
      if @picture.save
        format.html { redirect_to @picture, notice: 'Picture was successfully created.' }
        format.json { render json: @picture, status: :created, location: @picture }
      else
        format.html { render action: "new" }
        format.json { render json: @picture.errors, status: :unprocessable_entity }
      end
    end
  end
  </code></pre>
  
  <p>When receiving the request, "rails server" console says something like following</p>
  
  <pre><code>Started POST "/pictures/" for y.y.y.y at 2012-09-03 18:23:00 +0900
  Processing by PicturesController#create as HTML
    Parameters: {"picture"=&gt;{"name"=&gt;"PictureName"}}
     (0.1ms)  begin transaction
    SQL (0.5ms)  INSERT INTO "pictures" ("album_id", "created_at", "image_content_type", "image_file_name", "image_file_size", "image_updated_at", "name", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)  [["album_id", nil], ["created_at", Mon, 03 Sep 2012 09:23:00 UTC +00:00], ["image_content_type", nil], ["image_file_name", nil], ["image_file_size", nil], ["image_updated_at", nil], ["name", "PictureName"], ["updated_at", Mon, 03 Sep 2012 09:23:00 UTC +00:00], ["user_id", nil]]
  [paperclip] Saving attachments.
     (11.0ms)  commit transaction
  Redirected to http://x.x.x.x:3000/pictures/10                                                                                                                               
  Completed 302 Found in 15ms (ActiveRecord: 11.6ms)
  </code></pre>
  
  <p>As you can see, there's only one paramater sent and "picture[image]" parameter which is raw image data is not received. Can anyone help me?</p>