I need to upload a large file (7GB) in streaming mode (one piece at a time) on my web server made in asp .net core 5.
Configuration Server side:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = long.MaxValue;
});
});
}
Controller in Server Side:
[HttpPost]
[RequestFormLimits(MultipartBodyLengthLimit = Int32.MaxValue)]
public async Task PostStream(IFormFile formFiles)
{
//rest of code
}
Client Side ( Desktop app )
using (var httpClient = new HttpClient())
{
using (var content = new MultipartFormDataContent())
{
string fileName = @"D:\largeFile.zip";
FileStream fileStream = File.OpenRead(fileName);
HttpContent fileStreamContent = new StreamContent(fileStream);
fileStreamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "formFiles", FileName = fileName };
fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
content.Add(fileStreamContent);
var response = httpClient.PostAsync("http://localhost:5000/weatherforecast", content).Result;
response.EnsureSuccessStatusCode();
}
The system works up to 1 GB, with large files (7GB) the server cancels the request, I noticed that the files that are sent to the server are not streaming but upload them completely, I was expecting a progressive upload on the server as it happens on WCF. How can i send a file to the server progressively?