upload images

Topics: Web Api
Jul 26, 2011 at 3:51 PM
Edited Jul 27, 2011 at 8:21 AM

I'm trying to upload an obj that contains a list of images

uplaoding an image < 65536 works fine, but if bigger I got "Cannot write more bytes to the buffer than the configured maximum buffer size: 65536"

I presume isuue is on server side that does not allow big data stream.

according to http://pastebin.com/CNjyMuhL I created "CustomServiceHostFactory" as per sample, but still does not working

RouteTable.Routes.MapServiceRoute<WcfRestService1.Server.UserResource, CustomServiceHostFactory>("User", userConfiguration, null);

            var httpClient = GetHttpClient(_baseUri);
            var content = new ObjectContent<UserWithGallery>(user, new[] { new XmlMediaTypeFormatter() });
            content.Headers.ContentType = new MediaTypeHeaderValue("application/xml");
            var responseMessage = httpClient.Put(finalUri, content);//error throwed as above
            var responseContent = responseMessage.Content.ReadAs<UserWithGallery>(new[] { new XmlMediaTypeFormatter() });
            return responseContent;

I found the "issue" is at client side, not server. System.Net.Http.HttpContent has an internal cost to 65536.
internal const int DefaultMaxBufferSize = 65536; // 64KB

what am I missing? why that restriction?

After some investigation I found this solution in order to set programmatically MaxRequestContentBufferSize

            var httpClient = GetHttpClient(_baseUri);
            httpClient.Channel = new HttpClientChannel() { MaxRequestContentBufferSize=1024*1024 };

any thought on this? any better approach?