413 even when DisableRequestSizeLimit
I'm trying to upload my video 18 seconds to my API but seem that the
DisableRequestSizeLimit
is work
Backend
[HttpPost("{petShortId}"), DisableRequestSizeLimit]
public async Task<IActionResult> UploadVideo(int petShortId,
IFormFile video,
CancellationToken cancellationToken)
{
var petShort = await _petShortsRepository.FindByIdAsync(petShortId, cancellationToken);
if (petShort == null)
return NotFound("Not Found This Short");
var petaverMediaDTO = await _petShortService.UploadPetShortVideo(petShort,
video,
_azureStorageConfig.CurrentValue.PetaversePetVideos,
cancellationToken);
return petaverMediaDTO is null
? BadRequest("Can't save petshort video")
: Ok(petaverMediaDTO);
}
[HttpPost("{petShortId}"), DisableRequestSizeLimit]
public async Task<IActionResult> UploadVideo(int petShortId,
IFormFile video,
CancellationToken cancellationToken)
{
var petShort = await _petShortsRepository.FindByIdAsync(petShortId, cancellationToken);
if (petShort == null)
return NotFound("Not Found This Short");
var petaverMediaDTO = await _petShortService.UploadPetShortVideo(petShort,
video,
_azureStorageConfig.CurrentValue.PetaversePetVideos,
cancellationToken);
return petaverMediaDTO is null
? BadRequest("Can't save petshort video")
: Ok(petaverMediaDTO);
}
1 Reply
Frontend
public async Task<PetaverseMedia> UploadVideoAsync(PetShort petShort, StorageFile video)
{
if (video != null)
{
var multipartFormContent = new MultipartFormDataContent();
var handle = video.CreateSafeFileHandle(options: FileOptions.RandomAccess);
var stream = new FileStream(handle, FileAccess.ReadWrite) { Position = 0 };
var media = new StreamContent(stream);
media.Headers.Add("Content-Type", "video/mp4");
multipartFormContent.Add(media, name: "video", fileName: $"{petShort.Title}");
try
{
var result = await _httpClient.PostAsync($"api/PetShorts/UploadVideo/{petShort.Id}", multipartFormContent);
string stringReadResult = await result.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PetaverseMedia>(stringReadResult);
}
catch (Exception ex)
{
await new HttpRequestErrorContentDialog()
{
Title = "Can't upload video"
}.ShowAsync();
return null;
}
}
else return null;
}
public async Task<PetaverseMedia> UploadVideoAsync(PetShort petShort, StorageFile video)
{
if (video != null)
{
var multipartFormContent = new MultipartFormDataContent();
var handle = video.CreateSafeFileHandle(options: FileOptions.RandomAccess);
var stream = new FileStream(handle, FileAccess.ReadWrite) { Position = 0 };
var media = new StreamContent(stream);
media.Headers.Add("Content-Type", "video/mp4");
multipartFormContent.Add(media, name: "video", fileName: $"{petShort.Title}");
try
{
var result = await _httpClient.PostAsync($"api/PetShorts/UploadVideo/{petShort.Id}", multipartFormContent);
string stringReadResult = await result.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PetaverseMedia>(stringReadResult);
}
catch (Exception ex)
{
await new HttpRequestErrorContentDialog()
{
Title = "Can't upload video"
}.ShowAsync();
return null;
}
}
else return null;
}