Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 09, 2013 06:40 PM by vdtrip
Jan 05, 2013 01:34 AM|LINK
I am working on a wcf rest api. I got issue to upload images from Client side to API. From Client side I do POST method to pass Streaming, and In Service, trying to fetch data through Message, StreamReader and some other ways also tried.
I checked in debugging mode, stream has length of 15000 in Client Side, and when I recieve it in service, it is more than 15000, it is 21000.
I am not getting any idea why some extra values are added in Stream.
Please some one give idea to solve this issue.
Jan 07, 2013 12:57 PM|LINK
Check this article-
Check this in your config file-
and make it to maximum for the testing purpost.
Jan 09, 2013 06:40 PM|LINK
Finally I got the solution.
WCF REST API...
public DealerImage PostImage(Stream sm)
System.Drawing.Bitmap imag = new System.Drawing.Bitmap(sm);
byte imagedata = ImageToByte(imag);
//Save byte code to database..
public static byte ImageToByte(System.Drawing.Image img)
ImageConverter converter = new ImageConverter();
return (byte)converter.ConvertTo(img, typeof(byte));
Client Code to POST image.......
public void PostData()
byte fileToSend = null;
string name = "";
name = FileUpload1.FileName;
Stream stream = FileUpload1.FileContent;
fileToSend = new byte[stream.Length];
int count = 0;
while (count < stream.Length)
fileToSend[count++] = Convert.ToByte(stream.ReadByte());
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("URL here");
req.Method = "POST";
req.ContentType = "application/octet-stream";
req.ContentLength = fileToSend.Length;
Stream reqStream = req.GetRequestStream();
reqStream.Write(fileToSend, 0, fileToSend.Length);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream());
string result = reader.ReadToEnd();
catch (Exception ex)