如何在自托管(AppSelfHostBase)Servicestack服务(RequestStream)上设置文件大小限制?

时间:2019-07-28 17:35:01

标签: c# .net-core servicestack

使用AppSelfHostBase的自托管服务堆栈主机具有一种服务方法:

public object Any(UploadImageRequest request)
{
     // Need to make sure the file is not too large!
}

[Route("/UploadImage")]
public class UploadImageRequest : IRequiresRequestStream
{
    public Stream RequestStream { get; set; }
}

1 个答案:

答案 0 :(得分:2)

我实际上找到了一种可能的方法:

     public object Any(UploadImageRequest request)
     {
            if (Request.ContentLength > 10 * 1024 * 1024)
            {
                return new HttpResult($"Image too large!", HttpStatusCode.RequestEntityTooLarge);
            }
            ...
     }