Search code examples
objective-cwcfrestrestkit

Can't upload binary data via RestKIT 0.22 - server receives 0 length stream


our server is WCF and has a method that accepts binary data and stores it:

[WebInvoke(Method = "POST", //@WSF-687
     BodyStyle = WebMessageBodyStyle.WrappedRequest,
     ResponseFormat = WebMessageFormat.Json,
     UriTemplate = "File/{fileName}")]
ContentResponse UploadFile(string fileName, Stream fileStream);

our client side is objective-c and we are trying to post an object (image / etc...) to the server using RESTKit - but the stream in the other side is always 0 with no content...

Restkit code:

NSData* rawData //this is the data we want to send
[[RKObjectManager sharedManager] postObject: data path:OUR_SERVER_PATH parameters:nil success:nil failure: nil]

the call succeeds but the server receives empty stream..

when we used another method of creating form data - it worked but it appended the form data to the content which is problematic (we need it raw).

anything we missed?

thanks!


Solution

  • For uploading raw data with no other formatted (JSON / XML) data you should not be using RestKit, that isn't what it's for. You have access to AFNetworking, or you could use the Apple provided API, and these are much more suitable for your requirement.