How to pass file & additional data from angular to .Net 8 web API

Discussão em 'Angular' iniciado por FullStackFledling, Novembro 2, 2024.

  1. Hi I have recently upgraded .NET6 to .NET8 where one of the existing API which accepts IFormFile and string data got impacted like the string data is coming as empty. As far as I know in .NET8 the [FromForm] attribute is not needed so I removed that from the Angular UI and passing it as formdata. Not sure why still the data is coming as empty but file is passed. Can anyone help how to resolve this

    My API sample

    From UI I will be passing as form

    public async Task<ActionResult> upload(IFormFIle file, string data){

    }


    upload(file: File, data: string): Observable<any> {
    const formData: FormData = new FormData();
    formData.append('file', file, file.name);
    formData.append('data', data);

    return this.http.post(this.apiUrl, formData);
    }

    Continue reading...

Compartilhe esta Página