marcwan / LearningNodeJS

Source code to accompany my book, "Learning Node.JS"
280 stars 245 forks source link

Cannot display jpeg image through browser or curl #1

Closed cheesepencil closed 11 years ago

cheesepencil commented 11 years ago

Copied verbatim from book and from git repo - pointing app towards jpg url ends up serving broken jpg. Tried with multiple images.

Browser will not display image, firefox says: "The image “http://localhost:8080/content/example.jpg” cannot be displayed because it contains errors."

Using curl -o test.jpg localhost:8080/content/example.jpg returns a corrupted jpg file, opening the test.jpg with gthumb says: "Error interpreting JPEG image file (Not a JPEG file: starts with 0xef 0xbf)"

What is wrong?

cheesepencil commented 11 years ago

using node version v0.10.15

marcwan commented 11 years ago

Hi! Just back from vacation, let me take a look at this when I wake up tomorrow morning. What sample are you trying to run? What platform are you running on?

cheesepencil commented 11 years ago

Welcome back! I hope you had a safe and pleasant trip.

I'm working my way through chapter 6, and in particular the simple file server script after the modifications to add the file types other than html (at the point we add the switch conditional that reads the file extension).

I'm running on node built from source (left the version number in a comment on the git issue, I'm on mobile right now so I'm not sure of the top of my head which version) on stable Linux mint desktop.

Ultimately I'll be hosting my node apps on ubuntu server or some other debianesque server distro.

Thanks!

cheesepencil commented 11 years ago

specifically the script here (I didn't realize the new issue was just for the project generally, i thought I was adding an issue to 02_static_content_server.js): https://github.com/marcwan/LearningNodeJS/blob/master/Chapter06/02_static_content_server.js

Linux Mint 14 Cinnamon 32-bit Kernel 3.5.0-17-generic

marcwan commented 11 years ago

Hi!

Sorry, the d.toString("utf8") is incorrect. I've checked in a bug fix (c3c69a3254 ) that removes that, and will try to get it fixed for the next version.

Thanks for the report!

cheesepencil commented 11 years ago

Was it working when the book went to print? Did a node update break previously working functionality?

What was the point of converting the object to a UTF-8 string in the original code if the fix is to just send all the data straight to the buffer?

It works, though - sends image data and text to the browser! Thanks!

marcwan commented 11 years ago

I changed a LOT of code a LOT of times as I wrote the book, and on occasion, some code that was meant for something else got re-tasked and in my last testing phase, only tested it with text formats, I'm guessing. D'oh!