my question is, how can i edit or throttle the upload speed when i upload a file to my ASP.Net core web API. We have many clients with very very slow internet, so when the program starts uploading files, the entire bandwidth is used and nothing can be done on the internet. I have 2 code examples here:
1:Client:
class Program
{
static void Main(string[] args)
{
FileStream stream = new FileStream(@"C:\TEMP\te...", FileMode.Open);
Upload(stream).Wait();
}
public static async Task Upload(FileStream image)
{
using (var client = new HttpClient())
{
var content = new MultipartFormDataContent();
content.Add(new StreamContent(image), "te...");
try
{
HttpResponseMessage response =
await client.PostAsync("https://localhost:5001/api/uploadtest", content);
var cont = await response.Content.ReadAsStringAsync();
Console.WriteLine(cont);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadKey();
}
}
}
2:ASP.Net Core Web-API
[Route("api/[controller]")]
[ApiController]
public class UploadTestController : ControllerBase
{
Stream stream;
// POST api/<UploadTestController>
[DisableRequestSizeLimit]
[HttpPost]
public async Task<IActionResult> Post()
{
stream = Request.Body;
try
{
using (var fstream = System.IO.File.OpenWrite(@"F:\TMP\te..."))
{
await stream.CopyToAsync(fstream);
}
return Ok("test");
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
return BadRequest();
}
}
}