Skip to content

Arrays of strings and multipart/form-data #674

Open
@dluc

Description

@dluc

I'm writing a function with multipart/form-data, with this signature:

[Function("UploadFile")]
[OpenApiOperation("UploadFile")]
[OpenApiRequestBody(bodyType: typeof(UploadFileRequest), contentType: "multipart/form-data")]
[OpenApiResponseWithBody(bodyType: typeof(UploadFileResponse), contentType: "application/json")]
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest httpRequest)

receiving multipart/form data that contains a file and one array of strings.

public class UploadFileRequest
{
    public byte[] File { get; set; } = [];
    public List<string> Metadata { get; set; } = [];
}

swagger.json describes metadata as

{
    "name": "metadata",
    "description": "",
    "type": "array",
    "items": {
        "type": "string"
    },
    "in": "formData"
}

Swagger UI allows to enter strings, e.g.

Image

Problem

On the service side, metadata is received as a single value.

For instance, swagger UI suggested curl is:

curl -X POST ... -H  ... -F "metadata=a=1,b=2" -F "[email protected];type=image/png"

but the request should be:

curl -X POST ... -H  ... -F "metadata=a=1" -F "metadata=b=2" -F "[email protected];type=image/png"

Questions

  • Is there a way to say that a list of strings is sent as multiple and separate entries?
  • if not - Is there a way to say strings must be encoded and separated with a special char (the special char must be encoded if part of a value)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions