Skip to content
Juan Pablo Alcalá edited this page Jan 19, 2018 · 24 revisions

How to receive a Multi-part request

You can receive multi-part request if you include this static method (from http://stackoverflow.com/questions/7460088/reading-file-input-from-a-multipart-form-data-post):

private static async Task ParseFiles(Stream data, string contentType, Action<string, Stream> fileProcessor)
        {
            var streamContent = new StreamContent(data);
            streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType);

            var provider = await streamContent.ReadAsMultipartAsync();

            foreach (var httpContent in provider.Contents)
            {
                var fileName = httpContent.Headers.ContentDisposition.FileName;

                if (string.IsNullOrWhiteSpace(fileName))
                {
                    continue;
                }

                using (var fileContents = await httpContent.ReadAsStreamAsync())
                {
                    fileProcessor(fileName.Replace("\"", ""), fileContents);
                }
            }
        }

You need to include WebApi Client Nuget.

Also you can check the HttpMultipartParser Nuget and connect the Request input directly to the HttpMultipartParser, very helpful and small.

How to turn off logging

EmbedIO uses SWAN's Terminal to display all messages. You can disable them or change the verbosity by modifying the Terminal settings.

Terminal.Settings.DisplayLoggingMessageType = LogMessageType.None;