0

I'm new to this framework, can anyone tell me how to upload an image with other fields in a form to the server using POST?

Currently, I know how to send value from the fields using POST, but without image.

    let headers = new Headers({
      'Content-Type' : 'application/json'
    });
    let options = new RequestOptions({ headers: headers });

    let data = JSON.stringify({
      username: username, password: password
    });

    return this.http.post(this.baseUrl+"/login/auth", data, options)
        .map(res => res.json())
        .toPromise()
        .catch((error) => {
            console.log("Login failed");
            return Promise.reject(error);
        });

1 Answer 1

0

You should use fileTransfer for uploading files, you can send additional data in its options which you can access on your backend.

Other way to do it with http POST is to send base64 data of image , and regenerate it on your backend and save it to location. But that is nonsense , since your post url will be huge, sometimes wont even be able to send it whole.

I would recommend you reading about fileTransfers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.