0

I want to send an image from the server to the client but I get the following error:
Not allowed to load local resource: file:///C:/Users/path/to/image/MorphFace.jpg
This is how I make the send request: res.send(`${__dirname}\\uploads\\MorphFace.jpg`);

al21
  • 39
  • 5
  • That sounds like a browser error, not a node one.. were are you getting this error shown? – Keith May 05 '21 at 06:48
  • I think it almost works. I get another error after using res.sendFIle :```Failed to load resource: the server responded with a status of 404 (Not Found)``` and the new path is: ```http://localhost:3000/%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%10JFIF%EF%BF%BD%01%01....``` – al21 May 05 '21 at 06:51
  • The error from the post was in the console of the browser – al21 May 05 '21 at 06:53
  • The error just tells you the path is incorrect. You can resolve it by using the node build in [path](https://nodejs.org/api/path.html) module. Like: `res.sendFile(path.join(__dirname, '/uploads/MorphFace.jpg'))`. We don't know your folder structure so this is just a guess based on your question. – Reyno May 05 '21 at 06:58
  • Your trying to set the URL of an image to the binary response, at the browser you need to set the resource name, eg `app.get('bob', () => ...` the resource name is `bob` – Keith May 05 '21 at 06:59

0 Answers0