K
K
Konstantin Kudelko2017-09-20 11:49:42
JavaScript
Konstantin Kudelko, 2017-09-20 11:49:42

Is it possible to send the data along with the file to the server?

Hi all!
The question is, can I send any data with the file, the file is doing in FormData();
Backend - Node.js
Here is the service method:

public uploadAvatar(contactId, formData) {
        const token = '2agicftcnrpnpvio0askksatt9yb3m0lapvyvw17mra0rg4x6r2b12787phkw75isslyqq90y66r';
        const body = new URLSearchParams();
        const headers = new Headers({'Content-Type': 'multipart/form-data'});
        body.set('sessiontoken', token);
        body.set('type', 'contacts');
        body.set('identifier', contactId);
        body.set('file', formData);

        return this.http.post(`${this.API_URL}/files`, body, {headers: headers})
            .map(response => response.json());
    }

I get an error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Koch, 2017-09-20
@Flawming

You need to add sessiontoken, type, identifier data to formData:
https://developer.mozilla.org/en/docs/Web/API/Form...
and send formData in body

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question