You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
namespace HeartTrackAPI;
|
|
|
|
public class FileUploadSummary
|
|
{
|
|
public int TotalFilesUploaded { get; set; }
|
|
public string TotalSizeUploaded { get; set; }
|
|
public IList<string> FilePaths { get; set; } = new List<string>();
|
|
public IList<string> NotUploadedFiles { get; set; } = new List<string>();
|
|
}
|
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
|
|
public class MultipartFormDataAttribute : ActionFilterAttribute
|
|
{
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
{
|
|
var request = context.HttpContext.Request;
|
|
|
|
if (request.HasFormContentType
|
|
&& request.ContentType.StartsWith("multipart/form-data", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return;
|
|
}
|
|
|
|
context.Result = new StatusCodeResult(StatusCodes.Status415UnsupportedMediaType);
|
|
}
|
|
}
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
|
public class DisableFormValueModelBindingAttribute : Attribute, IResourceFilter
|
|
{
|
|
public void OnResourceExecuting(ResourceExecutingContext context)
|
|
{
|
|
var factories = context.ValueProviderFactories;
|
|
factories.RemoveType<FormValueProviderFactory>();
|
|
factories.RemoveType<FormFileValueProviderFactory>();
|
|
factories.RemoveType<JQueryFormValueProviderFactory>();
|
|
}
|
|
|
|
public void OnResourceExecuted(ResourceExecutedContext context)
|
|
{
|
|
}
|
|
} |