Server rejects FormData

Discussão em 'Angular' iniciado por NonameLover, Abril 3, 2025.

  1. NonameLover

    NonameLover Guest

    I have an Angular app that I have recently modified to use FormData to store user input data and a file I want to send over the server side.

    formData.append("photo", this.file);
    formData.append("obj", JSON.stringify(this.newObj))
    this.dataService.addObj(formData)


    the data service

    public addObj(formData: any): Promise<any> {

    return this.http
    .post(url, formData)
    .toPromise()}


    the service returns error 503 when I use the FormData data type but If send just the obj itself it works as expected. This: this.dataService.addObj(obj) works just fine. If I just append the obj (without the file) it still gives me the same error. I am using multer and here is the route

    the server route: router.post("/", upload.single("photo"), somemiddleware, objCreateFunction);

    Continue reading...

Compartilhe esta Página