0

I have issue with passing file inside form from Front-End to Backend. My file on backend side is always null. Front-End code:

public getTranslatedJson(
    json: File,
    destinatonLanguage: Language
  ) {
    const form = {
      "languageCharset": destinatonLanguage.systemId,
      "file": json
    }
    return this.http.post(this.url, form, {responseType: "blob", observe: "response"});
  };

Back-End code:

 [HttpPost("")]
    [Route("")]
    public IActionResult Post([FromForm] LanguageCharset languageCharset, [FromForm] IFormFile file)
    {
      var jsonString = new StringBuilder();
      using (var reader = new StreamReader(file.OpenReadStream()) // error here because file was null
      {
       [...]
jps
  • 20,041
  • 15
  • 75
  • 79
Obyi
  • 617
  • 1
  • 6
  • 13
  • Does this answer your question? [Angular File Upload](https://stackoverflow.com/questions/47936183/angular-file-upload) – Markus Apr 14 '21 at 08:12
  • @Markus No, because it's complete different approach. Mine approach works with a string instead of file, but i really want to use file there and want to achive that. – Obyi Apr 14 '21 at 08:31
  • IFormFile only works with files submitted via the form input component. – Erwin Apr 14 '21 at 12:33

0 Answers0