Skip to content

auto calculated boundary in large file uploading in asp.net core and testing with bombardier #99

Description

@Amit-limbasiya

What version of bombardier are you using?

Hash of the commit, like

00d7965d6cae34c62042abb0f6c45c45b870dcf3

What operating system and processor architecture are you using (if relevant)?

windows/amd64

What did you do?

i have written a code in asp.net core in minimal api as:

app.MapPost("/uploadFile", async (HttpContext context) => {

    string[] permittedExtensions = { ".pdf", ".bin", ".txt" };
    var boundary = HeaderUtilities.RemoveQuotes(MediaTypeHeaderValue
        .Parse(context.Request.ContentType).Boundary).Value;
    var reader = new MultipartReader(boundary, context.Request.Body, 524288000);
    var section = await reader.ReadNextSectionAsync();
    while (section != null)
    {
        if (ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition))
        {
            var fileExt = Path.GetExtension(contentDisposition.FileName.Value);
            if (string.IsNullOrEmpty(fileExt) || !permittedExtensions.Contains(fileExt) || !permittedExtensions.Contains(fileExt.ToLower()))
            {
                return Results.Problem(statusCode:415,title:"Invalid Extension");
            }
            if (contentDisposition.FileName.HasValue)
            {
                var fileName = Guid.NewGuid().ToString()+ contentDisposition.FileName.Value;
                using (var stream = new FileStream(Path.Combine(Path.GetTempPath(),fileName), FileMode.Create))
                {
                    await section.Body.CopyToAsync(stream);
                }
            }
        }
        section = await reader.ReadNextSectionAsync();
    }
    return Results.Ok("File uploaded successfully."); 
});

i had configure for max. 500mb size as

builder.Services.Configure<KestrelServerOptions>(options =>
{
    options.Limits.MaxRequestBodySize = 524288000;
});
builder.Services.Configure<FormOptions>(options =>
{
    options.MultipartHeadersLengthLimit = 524288000;
    options.MultipartBoundaryLengthLimit = 524288000;
    options.MultipartBodyLengthLimit = 524288000;
    options.ValueLengthLimit = 524288000;
    options.BufferBodyLengthLimit = 524288000;
}
);

What actually happened?

when i tried to sent the request from postman it has header conf. like
Content-Type: multipart/form-data; boundary=
Content-Length:
Host:

and it will upload the file successfully at temp folder.

but when i tried it with bombardier as:
bombardier -c 1 -n 1 -m POST --header="Content-Type: multipart/form-data; boundary= " --header="Content-Length:524288000" -f "Report.pdf" "https://localhost:7246/uploadFile" --http1.

it is not working and gives error like
The header contains invalid values at index 0: 'multipart/form-data; boundary= '

how to solve this problem?
basically, I am taking the pdf file as an input from user and wants to upload at my temp.folder and when i run on postman it will take random boundary automatically, how to made it work on bombardier that it will take random boundary and upload fle as postman.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions