SetSaveStream and HTTP 415 The content type 'plain/text;charset=utf-8' is not supported.

Feb 2, 2012 at 11:53 PM

Hello, I am trying to use the OData Client of Objective-C library on a Odata service I created in my application.

Entities management works fine, however when trying to use the setSaveStream method I get the  error: 

The content type 'plain/text;charset=utf-8' is not supported. (Http error 415).

My service is based on a MSDN sample called "PhotoService", it's written in C# and runs on a IIS7 web server. (http://msdn.microsoft.com/en-us/library/ee960144.aspx)

This happens if I am trying to create a new entity as well as if I am trying to add the stream (a picture) to an existing entity.

The code is as follows:

Model_Box *newItem = [[Model_Box alloc] init];
[proxy addToBoxes:newItem];
NSData *pictureData = [NSData dataWithContentsOfFile:self.pictureFile];
[proxy setSaveStream:newItem stream:pictureData closeStream:NO contentType:@"image/jpeg" slug:@"nuovofile.jpg"];
[proxy saveChanges];

 

This is taken exactly from the documentation. *newItem is an item that does not exist already in the entities collection, it should be created when this code is executed.

And in fact, if I remove the "setSaveStream" line, the insertion works fine.

Thank you in advance for replies. If there are anything I can do to better clarify the issue please let me know.

Giovanni

Feb 3, 2012 at 9:42 AM

I managed to solve the "content-type not supported" problem by manually editing the .edmx file of the model, and adding the m:hasStream attribute to the entity for which I want to upload the picture, as in the PhotoStream sample I mentioned on the above post.

However, the problem is now that the program returns a ODataServiceException "The network connection was lost", whenever I try to call [proxy saveChanges] or simply [proxy setSaveStream ... ]

Any advice?

Thank you

Giovanni