vitalybibikov / AzureExtensions.Swashbuckle

This extension enriches Azure Functions with Swagger/ Open API support
https://www.linkedin.com/in/vitali-bibikov/
MIT License
67 stars 54 forks source link

multipart/form-data #96

Closed imrandyk closed 6 months ago

imrandyk commented 2 years ago

If there is a way to support multipart/form-data I'm not seeing? If it is supported how would you accomplish this? If not is there a plan or path to do this?

There is a need to send files as part of the form also.

Guilherme-Foppa commented 2 years ago

I try to configure to multipart/form-data but I don't, Is there way to configure ?

angelolsantos commented 1 year ago

Any news about this problem?

vitalybibikov commented 6 months ago

This is an example of working with multipart data when uploading file, if it's not suffice and issue is still relevant please reopen and add new description. Thanks

image

For binary file upload

        [ProducesResponseType(typeof(TestModel), (int)HttpStatusCode.Created)]
        [RequestHttpHeader("x-ms-session-id", true)]
        [Function("TestUpload")]
        [SwaggerUploadFile("Pdf", "Pdf upload")]
        public async Task<IActionResult> TestUpload(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "test/upload")] HttpRequest req)
        {
            var data = await req.ReadFormAsync();

            if (data != null)
            {
                foreach (var formFile in data.Files)
                {
                    using var reader = new StreamReader(formFile.OpenReadStream());
                    var fileContent = await reader.ReadToEndAsync();
                    return new OkObjectResult(fileContent.Length);
                }
            }

            return new NoContentResult();
        }