Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //отправка
- private async Task SendFileSomewhere(Stream stream)
- {
- using var request = new HttpRequestMessage()
- {
- Method = HttpMethod.Post,
- RequestUri = new Uri("https://localhost:44301/FuckingFileSend"),
- Content = new StreamContent(stream),
- };
- using var response = await http.SendAsync(request);
- // TODO check response status etc.
- }
- //принятие
- private const long MaxFileSize = 10L * 1024L * 1024L * 1024L; // 10GB, adjust to your need
- [RequestSizeLimit(MaxFileSize)]
- [RequestFormLimits(MultipartBodyLengthLimit = MaxFileSize)]
- [Route("/FuckingFileSend")]
- public async Task ReceiveFile()
- {
- var boundary = HttpContext.Request.GetMultipartBoundary();
- // var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType));
- var reader = new MultipartReader(boundary, Request.Body);
- // note: this is for a single file, you could also process multiple files
- MultipartSection section = null;
- try
- {
- section = await reader.ReadNextSectionAsync();
- }
- catch(Exception e)
- {
- //вот тут ловлю исключение Multipart body length limit 16384 exceeded"
- }
- var fileName = contentDisposition.FileNameStar.ToString();
- if (string.IsNullOrEmpty(fileName))
- {
- fileName = contentDisposition.FileName.ToString();
- }
- using var fileStream = section.Body;
- // await SendFileSomewhere(fileStream);
- string path = Path.Combine(environment.ContentRootPath, "upload", fileName);
- using var Stream = new FileStream(path, FileMode.Create);
- fileStream.CopyTo(CurrentStreams.First().Value);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement