I'm having a serious problem and searched for many hours without finding a solution.
I have a backend server using Ruby of Rails and paperclip for image saving.
The image upload works fine from the browser, POSTing to /pictures
But when I try to upload it to /pictures.json using a multipart request with RestKit (iOS), I get a 406.
When the image (Picture object) is created server-side, a reward (Reward object) is associated to it. This reward object is what I'm expecting as a JSON response.
Here is the Objective-C code:
NSMutableURLRequest* uploadRequest = [self.objectManager multipartFormRequestWithObject:nil method:RKRequestMethodPOST
path:@"/pictures.json"
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData
appendPartWithFileData:UIImagePNGRepresentation(socialReward.image)
name:@"picture[pict]"
fileName:imageName
mimeType:@"image/png"];
}];
Here is the controller:
@picture = Picture.create( params[:picture] )
respond_to do |format|
format.html {
redirect_to @picture.reward
}
format.js {
render :json => @picture.reward.to_json(:include => :picture)
}
end
The CSRF check is disabled.
When comparing the requests from the browser and iOS using Wireshark, they are extremely similar.
Thanks in advance for your help.