Я пытаюсь загрузить очень большие видеофайлы (8 ГБ +) в хранилище Azure через приложение ASP.net Core, размещенное на Kestrel.
Я следовал документам здесь и изменилнесколько вещей для работы с хранилищем BLOB-объектов. Все работает с меньшим файлом, скажем 256 МБ, но когда они становятся больше, я получаю следующую ошибку:
System.IO.IOException: The read operation failed, see inner exception. --->
Microsoft.AspNetCore.Connections.ConnectionAbortedException:
The connection was timed out by the server.
Вот мой код:
[HttpPost("~/api/uploadMediaAssets")]
[RequestSizeLimit(long.MaxValue)]
[RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
[DisableFormValueModelBindingAttribute]
[Authorize]
public async Task<IActionResult> UploadMediaAsset([FromQuery]long courseId) {
var _defaultFormOptions = new FormOptions();
if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) {
ModelState.AddModelError("File",
$"The request couldn't be processed (Error 1).");
// Log error
return BadRequest(ModelState);
}
var boundary = MultipartRequestHelper.GetBoundary(
MediaTypeHeaderValue.Parse(Request.ContentType),
_defaultFormOptions.MultipartBoundaryLengthLimit);
var reader = new MultipartReader(boundary, HttpContext.Request.Body);
var section = await reader.ReadNextSectionAsync();
int index = 0;
while (section != null) {
var hasContentDispositionHeader =
ContentDispositionHeaderValue.TryParse(
section.ContentDisposition, out var contentDisposition);
if (hasContentDispositionHeader) {
// This check assumes that there's a file
// present without form data. If form data
// is present, this method immediately fails
// and returns the model error.
if (!MultipartRequestHelper
.HasFileContentDisposition(contentDisposition)) {
ModelState.AddModelError("File",
$"The request couldn't be processed (Error 2).");
// Log error
return BadRequest(ModelState);
} else {
// Don't trust the file name sent by the client. To display
// the file name, HTML-encode the value.
var trustedFileNameForDisplay = WebUtility.HtmlEncode(
contentDisposition.FileName.Value);
var trustedFileNameForFileStorage = Path.GetRandomFileName();
var asset = media.CreateAsset(trustedFileNameForDisplay);
// Connect to Azure
CloudBlobClient blobClient = mediaAssetStorageAccount.CloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(asset.ContainerName);
//CloudBlobContainer container = new CloudBlobContainer(new Uri(asset));
CloudBlockBlob blockBlob = container.GetBlockBlobReference(trustedFileNameForDisplay);
var streamedFileContent = await FileHelpers.ProcessStreamedFile(
section, contentDisposition, ModelState);
if (!ModelState.IsValid) {
return BadRequest(ModelState);
}
await blockBlob.UploadFromByteArrayAsync(streamedFileContent, index, streamedFileContent.Length);
index = index + streamedFileContent.Length;
}
}
// Drain any remaining section body that hasn't been consumed and
// read the headers for the next section.
section = await reader.ReadNextSectionAsync();
}
return Created("Success", null);
}