0

I'm getting a string from the database that has base64 encoded Image like this res.send(user.img). here is what I'm getting:

JSON from the server

All I want is to get this string:

The string that I'm trying to get

But here is what happens when I try to specify the value that I need like this res.send(user.img.data):

data transforms into crazy gibbersih

Crazy, right? I just want to get that string and for it to be normal text and not gibberish. Please, help.

Here is how the object looks in the DB (notice how it looks properly here):

Object

Here is the fetch:

app.post("/getImage", (req, res)=>{
   User.findOne({ login: "name" })
     .then((user) => res.send(user.img.data))
     .catch((error) => {
       console.log(error);
       res.send(500)
     });
 })

Here is what i'm doing in Postman:

Postman

14
  • Is this what are you looking for? stackoverflow.com/questions/2820249/… Commented Sep 7, 2021 at 8:40
  • I'm not trying to decode/encode anything. All I'm trying to do is to get that string that I already have and for it to not be symbols. Commented Sep 7, 2021 at 8:43
  • 1
    Please show your JS code, the code that fetches, logs and accesses the server's reply. Commented Sep 7, 2021 at 8:45
  • Here is the fetch: app.post("/getImage", (req, res)=>{ User .findOne({ login: "name" }) .then((user) => res.send(user.img.data)) .catch((error) => { console.log(error); res.send(500) }); }) Commented Sep 7, 2021 at 8:47
  • 1
    We need to see your client-side code. You posted a node/express route handler, i.e. server-side code. Commented Sep 7, 2021 at 8:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.