在typescript中,每个post方法发送多个参数

在typescript中,每个post方法发送多个参数,typescript,Typescript,我有以下代码,我想知道如何将变量凭据附加到它,以便我可以发送它,然后在后端读取它。 一定有办法附加不同的变量,但我不知道怎么做,有人能帮我吗?非常感谢 postFile(fileToUpload: File, credentials): Observable<boolean> { const endpoint = apiUrl + 'api/upload/files/'; const formData: FormData = new FormData(); f

我有以下代码,我想知道如何将变量凭据附加到它,以便我可以发送它,然后在后端读取它。 一定有办法附加不同的变量,但我不知道怎么做,有人能帮我吗?非常感谢

postFile(fileToUpload: File, credentials): Observable<boolean> {
    const endpoint = apiUrl + 'api/upload/files/';
    const formData: FormData = new FormData();
    formData.append('fileKey', fileToUpload, fileToUpload.name);
    return this.http
        .post(endpoint, formData, {
            headers: new HttpHeaders({
            })
        })
        .map(() => { return true; })

}
您可以尝试创建一个同时包含formData和凭据的对象,而不是将formData作为负载传递

例如:

postFile(fileToUpload: File, credentials): Observable<boolean> {
    const endpoint = apiUrl + 'api/upload/files/';
    const formData: FormData = new FormData();
    formData.append('fileKey', fileToUpload, fileToUpload.name);
    return this.http
        .post(endpoint, {credentials, formData}, {
            headers: new HttpHeaders({
            })
        })
        .map(() => { return true; })

}
{
    credentials: credentials,
    formData: formData
}