Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Amit-limbasiya opened this issue Apr 26, 2023 · 3 comments

Comments

@Amit-limbasiya
Copy link

Amit-limbasiya commented Apr 26, 2023

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.

@codesenberg
Copy link
Owner

Another user previously encountered similar issue in #21. In short, currently you'll have to craft the body yourself.
It should be possible to implement a feature that would provide something similar to what cURL offers.

@codesenberg codesenberg added this to the Unplanned milestone Apr 27, 2023
@Amit-limbasiya
Copy link
Author

thanks @codesenberg, just need one confirmation for what i have understood, currently i have to craft body manually to use bombardier but curl set auto-boundary and wrap the content of file with the boundary. right?

@codesenberg
Copy link
Owner

That's right.

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

No branches or pull requests

2 participants