./src/components/FileUpload.js Line 22:9: 'cons' is not defined no-undef Line 23:9: 'formData' is not defined no-undef Line 24:9: 'formData' is not defined no-undef Line 25:9: 'formData' is not defined no-undef Line 29:13: 'cons' is not defined no-undef
As I said, both of the lines of code have an issue, and the error points out that you have not defined formData. Specifically, you have not initialisedformData.
Again, this has to do with the basic syntax of JavaScript, so I highly recommend going through the first few lessons of the above linked course.
This is one of a few posts that you’ve made asking for help with something that you don’t understand, seeming to reveal a lack of familiarity with some of the fundamentals. It’s like you’ve skipped over the Basic Auto Mechanics class and are trying to build your custom car from scratch.
While it’s perfectly OK to post here about things other than the curriculum, this forum is part of Free Code Camp which has a curriculum that would make you very ready for things like this. I agree with the others that this would be a lot better for you to learn the fundamentals. It may not be as much fun as working on a big project, but it would be the best thing for your development as a coder.
Thanks for your advice I don’t have any error now.
But when I upload an image, it doesn’t being uploaded in wwwroot folder!
Did I use Axios in the above code correctly?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace imageEditor3
{
public class FileModel
{
public string FileName { get; set; }
public IFormFile FormFile { get; set; }
}
}
controller:
namespace imageEditor3.Controllers
{
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
/// <summary>
/// Defines the <see cref="FileController" />.
/// </summary>
[Route("api/file")]
[ApiController]
public class FileController : Controller
{
/// <summary>
/// The Post.
/// </summary>
/// <param name="file">The file<see cref="FileModel"/>.</param>
/// <returns>The <see cref="IActionResult"/>.</returns>
public IActionResult Post([FromForm] FileModel file)
{
try
{
string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", file.FileName);
using (Stream stream = new FileStream(path, FileMode.Create))
{
file.FormFile.CopyTo(stream);
}
return StatusCode(StatusCodes.Status201Created);
}
catch(Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}
}
I have used ASP.net core and Blazor. But this is a first-time use of javascript in view. I think in this example react can’t call the back end!
Something is wrong with Axios!
Then you should be able to diagnose this. This is trouble shooting. Can you dispatch that call in PostMan? What code does it get back? Does the server see the POST? Is it getting the data? Is the path being created correctly? Is the stream being created? Is it writing?
Right… but if you can’t answer those basic diagnosis problems, then you are lacking some fundamental knowledge. Again, I think your project is too ambitious for your level of knowledge. I really think you need to take a step back and build some fundamentals.
But stepping you through every problem you have AND having to tell you how to find the problem AND having to explain it to you is not the best use of my time and energy, especially since I don’t do ASP.net.