Как правильно сделать пост-вызов в Angular 9 для передачи файла в express -fileupload? - PullRequest
0 голосов
/ 06 мая 2020

я могу сделать это в почтальоне postman call working perfectly

Но в Angular не работает, это Angular код js:

<input type="file" #fileUpload id="fileUpload" name="file" multiple="multiple" accept=".csv"  />
const formData = new FormData();
    formData.append('file', file);

    this.caricautentiService.caricautenti(this.globals.idPersona,formData).subscribe( response => { 
        console.log(response);
    });

это услуга:

    if (file !== undefined) {
        formParams = formParams.append('file', <any>file) as any || formParams;

    }

    return this.httpClient.request<any>('post',`${this.basePath}/caricautenti/${encodeURIComponent(String(idpersona))}`,
        {
            body: formParams,
            withCredentials: this.configuration.withCredentials,
            headers: headers,
            observe: observe,
            reportProgress: reportProgress
        }
    );

Что мне не хватает? Любая помощь приветствуется, спасибо

1 Ответ

1 голос
/ 07 мая 2020

Это сработало для меня:

public addFileToProgram(file: any): Observable<any> {
    const formData = new FormData();
    formData.append('file', file, file.name);
    return this.http.post<any>('/v1/uploadfile', formData);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...