Posts

Showing posts from January, 2016

How to resolve file corruption after upload through WCF Service.

Recently I Implemented a WCF  Service to upload files. Implementation was fine and even file save to given location successfully, but  when I try to open these files I got error messages saying that the file is not encoded properly or file is too large to open. After searching I got a sample code to overcome that issue. You can check original Implementation in here  http://multipartparser.codeplex.com/ . Thanks Anthony for awesome code implementation.  

Upload Files using WCF Rest Service

1. Interface Class [ServiceContract] public interface IUpload { /// <summary> /// Upload, runs synchronously service side . /// </ summary > /// < param name="token">An application arbitrary piece of data. Can be used for request obfuscation.</ param > /// < param name="data">The data being uploaded.</param> [OperationContract] [WebInvoke(UriTemplate = "upload/{token}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] void Upload(string token, Stream data); } 2. Service Implementation Class public class UploadDataService : IUpload { public void Upload(string token, Stream data) { StreamToFile(data); } private void StreamToFile(Stream data) { // get full path to and create the directory to save file in ...