All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aspnetcore.2.1.Formatters.InputFormatterStream.mustache Maven / Gradle / Ivy

There is a newer version: 7.6.0
Show newest version
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Formatters;

namespace {{packageName}}.Formatters
{
    // Input Type Formatter to allow model binding to Streams
    public class InputFormatterStream : InputFormatter
    {
        public InputFormatterStream()
        {
            SupportedMediaTypes.Add("application/octet-stream");
            SupportedMediaTypes.Add("image/jpeg");
        }

        protected override bool CanReadType(Type type)
        {
            if (type == typeof(Stream))
            {
                return true;
            }

            return false;
        }

        public override Task ReadRequestBodyAsync(InputFormatterContext context)
        {
            return InputFormatterResult.SuccessAsync(context.HttpContext.Request.Body);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy