domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.25k stars 1.31k forks source link

[Bug]: [FromForm(Name = "file")] parameter #3055

Open Lean365 opened 2 months ago

Lean365 commented 2 months ago

Describe the bug

When using the [FromForm(Name = "file")] parameter, the swagger error code is as follows.

public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
{
            List<MmMarbDto> list = new();
            using (var stream = formFile.OpenReadStream())
            {
                list = stream.Query<MmMarbDto>(startCell: "A1").ToList();
            }

            return SUCCESS(_MmMarbService.ImportMmMarb(list.Adapt<List<MmMarb>>()));
}
08-29 10:51:08|::1|0HN67QLM2IATC|http://localhost/swagger/routine/swagger.json
Failed to generate Operation for action - Ams.WebApi.Controllers.Routine.InstCorpController.ImportData (Ams.WebApi). See inner exception
public IActionResult ImportData(IFormFile formFile)//[FromForm(Name = "file")]
{
            List<MmMarbDto> list = new();
            using (var stream = formFile.OpenReadStream())
            {
                list = stream.Query<MmMarbDto>(startCell: "A1").ToList();
            }

            return SUCCESS(_MmMarbService.ImportMmMarb(list.Adapt<List<MmMarb>>()));
}

Swagger is normal when not in use. 6.5 The following versions are normal using [FromForm(Name = "file")].

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

V6.6.1~6.7.3

.NET Version

net 8.0

Anything else?

No response

martincostello commented 2 months ago

Please provide a minimal reproducible example as a GitHub repository that demonstrates the issue you're experiencing so we can look into this further.

The code snippet as-written isn't particularly useful for debugging as it references code you haven't provided.

Also provide details of the inner exception mentioned in the error, particularly its stack trace.

Tri125 commented 4 weeks ago

@Lean365 From v6.6.x and onward Swashbuckle will throw an error when a user uses FromForm attribute with IFormFile in controller methods.

Have a look at this documentation for more information : Handle Forms and File Uploads