I'm new to the topic of http requests.
I am uploading an image from the client and send it to the server via a POST request. I should get an image back in the answer, because it works fine in Postman. Unfortunately it doesn't work in my code because the answer is not showing. Am I doing something wrong?
CodePudding user response:
Could it be this line? I think the body contains the entire image contents, judging by the postman response, require the raw postman response to be sure.
Before:
this.dbImage = 'data:image/jpeg;base64,' this.postResponse.image;
After:
this.dbImage = 'data:image/jpeg;base64,' this.postResponse.body;
CodePudding user response:
I solved it now:
My browser showed an error I didn't see before:
Access to XMLHttpRequest at 'http://localhost:8080/api/maze' from origin >'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control->Allow-Origin' header is present on the requested resource.
To solve this, I added
@CrossOrigin(origins = "http://localhost:4200")
to the spring boot controler. Now it can reach the server.