C#C
C#14mo ago
Alex

Upload file with swagger ui crash

I'm trying to upload IFormFIle with swagger ui and as soon as I select file and click select or cancel the backend application crashes without any error displayed. Can I fix it? Is it better to switch to Postman?
[HttpPost("upload")]
public async Task<IActionResult> Upload(IFormFile? formFile)
{
    if (formFile == null || formFile.Length == 0)
    {
        return BadRequest("No file uploaded.");
    }

    var putObjectArgs = new PutObjectArgs()
        .WithBucket(_config.BucketName)
        .WithObject(formFile.FileName)
        .WithObjectSize(formFile.Length)
        .WithContentType(formFile.ContentType)
        .WithStreamData(formFile.OpenReadStream());
    
    // TODO: check if object is uploaded to the bucket
    await _minio.PutObjectAsync(putObjectArgs);

    return Ok(new {message = "File uploaded to the bucket"});
}
image.png
image.png
Was this page helpful?