You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been scratching my head yesterday and today trying to see the errors of my ways. But I can't seem to get the AspNetCore.Docs\aspnetcore\mvc\models\file-uploads\samples\3.x\SampleApp solution to work.
I'm running on windows 10. and I've created the c:\files folder. I've manually copied over a file into the folder and started the web app. It lists the file in the GUI - so at least I know the read access is working.
I have also created a web.config file to prevent the IIS 413 errors I'm getting. It looks like this:
I've added .pdf and .mp4 files to the list of allowed file types in the streaming controller.
public class StreamingController : Controller
{
private readonly AppDbContext _context;
private readonly long _fileSizeLimit;
private readonly ILogger<StreamingController> _logger;
private readonly string[] _permittedExtensions = { ".txt",".mp4",".docx",".pdf"};
The GUI loads... and because I need to learn how to stream files in chunks, I'm trying the "Stream a file with AJAX to a controller endpoint" option under "Physical storage upload examples".
I pick a word doc (small) and I try to upload it. But the code fails with a 400 error. From what I can tee, it finds form data. I think it dies in StreamingController.cs file - UploadPhysical() method:
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
Console.WriteLine("This is where it dies");
return BadRequest(ModelState);
}
else
I don't know how to refactor the code to prevent it from finding form data.
I'm presently trying to remove the form tag in the HTML in StreamedSingleFileUploadPhysical.cshtml... but I have some syntax errors and the button isn't triggering anything anymore.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've been scratching my head yesterday and today trying to see the errors of my ways. But I can't seem to get the AspNetCore.Docs\aspnetcore\mvc\models\file-uploads\samples\3.x\SampleApp solution to work.
I'm running on windows 10. and I've created the c:\files folder. I've manually copied over a file into the folder and started the web app. It lists the file in the GUI - so at least I know the read access is working.
I have also created a web.config file to prevent the IIS 413 errors I'm getting. It looks like this:
This is what my appsettings (and appsettings.Development) looks like:
I've added .pdf and .mp4 files to the list of allowed file types in the streaming controller.
The GUI loads... and because I need to learn how to stream files in chunks, I'm trying the "Stream a file with AJAX to a controller endpoint" option under "Physical storage upload examples".
I pick a word doc (small) and I try to upload it. But the code fails with a 400 error. From what I can tee, it finds form data. I think it dies in StreamingController.cs file - UploadPhysical() method:
I don't know how to refactor the code to prevent it from finding form data.
I'm presently trying to remove the form tag in the HTML in StreamedSingleFileUploadPhysical.cshtml... but I have some syntax errors and the button isn't triggering anything anymore.
Any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions