title: RestKit image upload parameters
body: <p>I've made multiple attempts to enable POST image file transfer with RestKit but have only succeeded so far using curl. The working code is below, but it is synchronous and makes the UI unresponsive.</p>
  
  <pre><code>NSArray *arguments =
  [NSArrayarrayWithObjects:assetScriptFullPath,
    @"-F", [NSString stringWithFormat:@"asset[file]=@%@", fullPath],
    @"-F", [NSString stringWithFormat:@"asset[user_id]=%d", user_id],
    @"-F", [NSString stringWithFormat:@"asset[checksum]=%s", [(NSString *)md5hash UTF8String]],
    nil];
  NSTask *task = [NSTasklaunchedTaskWithLaunchPath:@"/usr/bin/curl"arguments:arguments];
  </code></pre>
  
  <p>The curl call is received at the server as below:</p>
  
  <pre><code>{
  "asset"=&gt;{
    "file"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0xcfcc630
      @original_filename="IMG_6236.JPG",
      @content_type="image/jpeg",
      @headers="Content-Disposition: form-data; name=\"asset[file]\"; filename=\"IMG_6272.JPG\"\r\nContent-Type: image/jpeg\r\n",
      @tempfile=#&lt;File:/tmp/RackMultipart20121117-21489-brm3b9&gt;&gt;,
    "user_id"=&gt;"522",
    "checksum"=&gt;"ab23bc492bac990d9022248315c743c1"
    }
  }
  </code></pre>
  
  <p>One attempt with RestKit is based on this post ( <a href="https://stackoverflow.com/questions/8438170/restkit-image-upload">RestKit Image Upload</a> ) but doesn't nest file within asset. My attempts to nest the params within 'asset' haven't worked or have crashed.</p>
  
  <pre><code>{
    "user_id"=&gt;"522",
    "checksum"=&gt;"ab23bc492bac990d9022248315c743c1",
    "file"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x883eb9c
      @original_filename="file",
      @content_type="image/jpeg",
      @headers="Content-Disposition: form-data; name=\"file\"; filename=\"file\"\r\nContent-Type: image/jpeg\r\n",
      @tempfile=#&lt;File:/tmp/RackMultipart20121125-25702-ac8ck9&gt;&gt;
  }
  </code></pre>
  
  <p>Using the method described in the RestKit advanced tutorial below I either can't get the hierarchy I need (file within asset) or I can't get the image data attached without crashing.
   <a href="https://github.com/RestKit/RestKit/blob/master/Docs/MobileTuts%20Advanced%20RestKit/Advanced_RestKit_Tutorial.md" rel="nofollow noreferrer">https://github.com/RestKit/RestKit/blob/master/Docs/MobileTuts%20Advanced%20RestKit/Advanced_RestKit_Tutorial.md</a>
  One way I tried to attach the image that causes crashes is described here:
  <a href="https://stackoverflow.com/questions/8203182/serialize-nested-image-in-restkit-rails-backend">Serialize nested image in RestKit (Rails Backend)</a></p>
  
  <pre><code>{
  "asset"=&gt;{
    "user_id"=&gt;"522", 
    "file"=&gt;"@/Users/dev/IMG_6236.JPG", 
    "checksum"=&gt;"ab23bc492bac990d9022248315c743c1"
    }
  }
  </code></pre>
  
  <p>Any recommendations? Thanks!</p>
  
  <hr>
  
  <p>If I could change what the server expects I can get it to work with a flat parameter hierarchy. This isn't a solution though, I can't change the hierarchy. The code is below:</p>
  
  <pre><code>[params setFile:asset forParam:@"file"];
  [params setData:[name dataUsingEncoding:NSUTF8StringEncoding] forParam:@"name"];
  [params setData:[user_id dataUsingEncoding:NSUTF8StringEncoding] forParam:@"user_id"];
  [client post:assetScriptPath params:params delegate:self];
  </code></pre>
  
  <p>This is what the server sees, but I need this all within an "asset" as above.</p>
  
  <pre><code>{
    "file"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0xcfcc630
      @original_filename="IMG_6236.JPG",
      @content_type="image/jpeg",
      @headers="Content-Disposition: form-data; name=\"file\"; filename=\"IMG_6272.JPG\"\r\nContent-Type: image/jpeg\r\n",
      @tempfile=#&lt;File:/tmp/RackMultipart20121117-21489-brm3b9&gt;&gt;,
    "user_id"=&gt;"522",
    "checksum"=&gt;"ab23bc492bac990d9022248315c743c1"
  }
  </code></pre>