1

I am trying to send a file and other data to an Asp-Core-BackEnd.

In the backendController, I read the file like:

IFormFile file = HttpContext.Request.Form.Files.First(); //don't work

HttpContext.Request.Form.TryGetValue("id", out id)  //works

Works for other Clients. But I want use the Api with JS.

My js-code (react) looks like this:

const formData = new FormData();      
formData.append('id', 123);
formData.append('files', files);  //don't work

const config = {
    headers: {
      'content-type': 'multipart/form-data; charset=utf-8; boundary="------";'
    }
  }
        
await axios.post(url, formData, config);

but Form.Files is an empty Array

1 Answer 1

3

Try this?

[HttpPost]
        public string getfile([FromForm] string id, [FromForm] IFormFile file) {
            return "success";
        }

enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.