Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone.

I would like to ask you, is it possible to send a post request in Angular with the link to the image that I want and then from the API get an image without using an HTTP.GET request but only an HTTP.POST one?

The reason why is because all the images I need are stored in a Synology NAS server on a different volume from where the actual website's front-end is, so they are not accessible (as far as I know) from Angular itself.

I have been using a GET request so far but I realised that if another user from another PC requests a different image the two images may be swapped and both the users will receive the wrong one or an error.

What I have tried:

I already tried in my Express server to:

res.sendFile(path.resolve(imagePath));


but then in the front end (in the inspector) I get

error: SyntaxError: Unexpected token � in JSON at position 0 


In the front-end I got
res=>
       {
         console.log("The path is set!", res)

         this.getImage(this.url_toService).subscribe(x => this.url = x);


         console.log("reciving from Recerive2");

       },


But because the error part of the callback is executed the code never gets to the
this.GetImage(...)
Posted
Updated 28-Sep-21 5:49am
v3

1 solution

At the end of the story I used this: node.js - How to copy a image? - Stack Overflow[^]
to copy the image that I needed where the front-end could reach it (in the volume where the web is).

But it would be great to hear if it is still possible to send an image as a Post request.
 
Share this answer
 
Comments
Richard MacCutchan 28-Sep-21 12:24pm    
Don't post additional information as a Solution; people will ignore the question if they think it is solved. Use the Improve question link above, and add to your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900