Не выходит из Angular загрузить изображение на сервер nodejs с помощь multer
У меня в Ангуляре есть форма с загрузкой файла(изображения), который нужно сохранить в папке на сервере. Но по каким-то причинам у меня этого не выходит, папка куда должны сохраняться изображения создалась, а вот изображения туда не сохраняются. Ошибок никаких не выдает
Моя форма в файле dashboard.component.html
<form action="setProfileImage" method="post" enctype="multipart/form-data">
<input hidden="true" type="file" name="filedata" id="file-input" (change)="onFileSelected($event)">
<label for="file-input">
<div mat-raised-button class="btn" class="userInfo__addFoto">
<p>Завантажити фото</p>
</div>
</label>
</form>
dashboard.component.ts
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../auth.service';
import { FlashMessagesService } from 'flash-messages-angular';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
selectedFile!: File;
userId=this.route.snapshot.params['id'];
constructor(
private flashMessages: FlashMessagesService,
private router: Router,
private authService: AuthService,
private route: ActivatedRoute
) { }
ngOnInit(): void {}
onFileSelected(event: any) {
this.selectedFile = <File>event.target.files[0];
const formData = new FormData();
formData.append('filedata',this.selectedFile);
console.log(formData);
this.authService.setImage(formData);
}
}
Функция в auth.service.ts
setImage(data: any) {
return this.http.post('http://localhost:3000/account/setProfileImage',
data);
}
Часть из кода отвечающая за этот функционал на сервере node.js
const upload = multer({dest:"uploads"});
router.post('/setProfileImage', upload.single("filedata"), (req, res) => {
filedata = req.file;
console.log(filedata);
if(!filedata)
res.send("Ошибка при загрузке файла");
else
res.send("Файл загружен");
});