I want to send an http POST request with a binary data from a file. I get a successful server respond when I do it via postman->Body->Binary->Choose file. see image:
But I can not figure out how to do it via Angular HttpClient. How can I finish the following:
set processImage(event) {
console.log(event);
let files: FileList = event.target.files;
let file = files[0];
//send the file as a binary via httpClient
....
Finally got it to work. Here's the code for future reference for anyone in need:
processImage(event) {
console.log(event);
let files: FileList = event.target.files;
let file : File = files[0];
this.http.post(URL, file).subscribe(
(r)=>{console.log('got r', r)}
)
For Sending binary Data in Angular you can use FormData example :
let file = event.target.files[0];
let url = 'your url';
let formData = new FormData();
formData.append("myfile", file);
this.http.post(url,formData).subscribe(
(res) => {
console.log('response', res)
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With