Response does not send back the correct data

#1

More details on StackOverflow.

When I retrieve my images which were streamed as described here, I am getting the data exactly as it is saved now as an image, even if I set the headers correctly:

response.header('content-type', file.tyle)
response.header('content-length', Buffer.byteLength(file.contents))
response.send(file.contents)

The the file.contents above before saving it to the database:

<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 98 00 00 00 98 08 06 00 00 00 18 c2 20 21 00 00 00 04 67 41 4d 41 00 00 b1 8f 0\
b fc 61 05 00 ... 5227 more bytes>

This is how it looks like inside the database table:

And this is what I get on the browser from the above code:

P.S. I stream the files directly to the database as shown in @virk 's answer linked here.

What is missing?

0 Likes

#2

Looks like an encoding issue, but you probably already know that, how to solve it I am not sure. Are there any tools that allow you preview images stored in the database, so you can check it is not getting corrupted as you stream it into the database.

Also are you sure that is not the picture that you uploaded. I would like that on my wall LOL :slight_smile:

Good luck finding a fix though.

1 Like

#3

Indeed, you are right, I think it is base64 encoded from I saw in the devtools. I shared 2 more screenshots on Stackoverflow that show I truly received the picture on the client side. I am sure just something very small is missing to display it right in the browser. I will keep trying :slight_smile:

1 Like