-
Hello friends, I encountered a problem when uploading a file, and I will share the code related to the issue below. When uploading a file using HttpClient, I use MultipartFormDataContent. When adding the file with the help of MultipartFormDataContent, the Content-Disposition appears as follows: [HttpPost]
public async Task<IActionResult> FileUpload(IFormFile file)
{
using HttpClient httpClient = new HttpClient();
using var formData = new MultipartFormDataContent();
formData.Add(new StreamContent(file.OpenReadStream()), "file", file.FileName);
HttpResponseMessage response = await httpClient.PostAsync("https://example.com/upload-endpoint", formData);
if (response.IsSuccessStatusCode)
{
//
}
return Ok(file.FileName);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I have a good question. I will be happy if you answer |
Beta Was this translation helpful? Give feedback.
-
If there is something about the format of the Something like using var formData = new MultipartFormDataContent();
var fileContent = new StreamContent(myStream);
formData.Add(fileContent, "file", file.FileName);
fileContent.Headers.Remove("Content-Disposition");
fileContent.Headers.TryAddWithoutValidation("Content-Disposition", "the custom value that you've validated to be safe to use because it won't be validated further"); cc: @dotnet/ncl |
Beta Was this translation helpful? Give feedback.
If there is something about the format of the
Content-Disposition
header value that your server does not understand, you should be able to manually add the exact value format you want via the existingTryAddWithoutValidation
method.Something like
cc: @dotnet/ncl