小编Sam*_*ino的帖子

使用 Swagger 5.0.0-rcX 和 .Net-Core 3 上传文件

我正在使用 .NetCore 3 和 Swagger 5.0.0-rc4。我正在尝试使用 Swagger 上传文件(图像)但它不起作用,因为 IOperationFilter 甚至 Swashbuckle.AspNetCore.Swagger 中的 apply 方法缺少一些属性。例如 NonBodyParameter 和 Consumes 不会在 Swagger 5.0 中退出

有没有人使用面临同样的问题或试图解决它?

public class FileOperationFilter : IOperationFilter
    {

        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            if (operation.OperationId.ToLower() == "apivaluesuploadpost")
            {
                operation.Parameters.Clear();
                operation.Parameters.Add(new **NonBodyParameter**
                {
                    Name = "uploadedFile",
                    In = "formData",
                    Description = "Upload File",
                    Required = true,
                    Type = "file"
                });
                operation.**Consumes**.Add("multipart/form-data");
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# file-upload swagger asp.net-core .net-core-3.0

5
推荐指数
2
解决办法
2310
查看次数

标签 统计

.net-core-3.0 ×1

asp.net-core ×1

c# ×1

file-upload ×1

swagger ×1