1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Issues with .NET 8 API Migration: string additionalData Parameter Coming in Empty for...

Discussão em 'Angular' iniciado por FullStackFledling, Novembro 3, 2024 às 15:02.

  1. I recently migrated my backend to .NET 8 and am encountering an issue with an upload API that used to work perfectly. Here’s the setup:

    I have an API method in my controller that accepts a file and an additional data string: Frontend (Angular):

    Task<ActionResult> Upload(IFormFile file, string additionalData){
    }


    const formData = new FormData();
    formData.append('file', this.selectedFile, this.selectedFile.name);
    formData.append('additionalData', JSON.stringify(param));

    upload(data: FormData): Observable<HttpResponse<any>> {
    return this.http.post<any>(this.apiUrl, data, { observe: 'response' });
    }



    Since moving to .NET 8, the additionalData parameter in the API is coming through as an empty string. I’ve confirmed that FormData contains both the file and the JSON string for additionalData when the request is sent.

    Is there something I need to adjust in .NET 8 to ensure the additionalData parameter is received correctly? Any guidance on why this might be happening and how to resolve it would be greatly appreciated!

    Thanks in advance for any help!

    public IActionResult UploadImage(FileInputModel inputdata)
    {

    return Ok();
    }

    public class FileInputModel
    {
    public IFormFile File { get; set; }
    public string Param { get; set; }
    }

    Continue reading...

Compartilhe esta Página