How to send an image per post at the angle

Asked

Viewed 202 times

0

I wonder how I can be sending an image to an api at Angular 6 through the post method.

First I must encode this image in base 64 and then I send all that coding as a key value????

1 answer

1

At Angular 6, you can send the image bits in the body of the POST request.

sendImage(imagem) {
  return this.httpClient.post(URL, imagem, {headers: this.headers});
}

And then the server would process the image bits and store the file in memory. You can use the same logic with the PUT request.

Sending through a GET request culminates in placing image bits in the request header.

  • What do you mean by sending the image bits? is via base 64 encoding?

  • Yes. If you use a type input file, you can associate a function to the event change (change)="funcao()", and every time the input value is changed, it performs this function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.