Forum How do I...?

Error rendering JPG img - Unknown image MIME type: text/html

mhinze
I am trying to render some images, but I keep seeing this error message: Unknown image MIME type: text/html

When I view the HTML from the browser, bypassing Prince, everything looks fine and I can see the images. In the generated PDF I only see the ALT text.

Here is the relevant HTML snippet:

<img src="http://localhost:8082/Photos/Arrests/057_TRN000000295X_Medium.jpg" alt="Image" />


Here is the log output:

Mon Nov 23 12:36:37 2009: ---- begin
Mon Nov 23 12:36:37 2009: Loading document...
Mon Nov 23 12:36:37 2009: http://localhost:8082/Photos/Arrests/057_TRN000000295X_Medium.jpg: warning: Unknown image MIME type: text/html
Mon Nov 23 12:36:37 2009: Converting document...
Mon Nov 23 12:36:37 2009: finished: success
Mon Nov 23 12:36:37 2009: ---- end


I checked with Firebug and the HTTP response looks like this:

Server	ASP.NET Development Server/9.0.0.0
Date	Mon, 23 Nov 2009 18:35:54 GMT
X-AspNet-Version	2.0.50727
Cache-Control	private
Content-Type	image/jpeg
Content-Length	8968
Connection	Close


We see this using the ASP.NET Development Server and also IIS on our production web server.

We are using the ASP.NET response feature like this:

string path = _configuration.GetPrincePath();
var prince = new Prince(path);
prince.SetBaseURL(Request.Url.AbsoluteUri);
prince.SetLog("prince.log");

Response.Clear();
Response.Filter = new PrinceFilter(prince, Response.Filter);
Response.AddHeader("Content-Type", "binary/octet-stream");
Response.AddHeader("Content-Disposition", "attachment; filename=Report.pdf;");


This does not affect all images. We are in control of the encoding of most of these images, so we can change that if there is something strange we are doing or if Prince has strange requirements. :)

We are using Prince for Windows that I downloaded from princexml.com today. I have attached the exact file (it's obviously a test image, but it was uploaded and processed like the real ones) so that you can inspect it.
  1. 057_TRN000000295X_Medium.jpg3.7 kB
mikeday
Are you sure that all the images are being served up with the correct MIME type? The browsers will sometimes cheat by sniffing the file and ignoring the specified MIME type, but we were hoping not to have to do that. A tool like curl or wget is handy for checking the response type without any content sniffing.
mhinze
It wouldn't have mattered, the problem was unrelated to my images or Prince. I should have used wget to troubleshoot immediately - would have saved me a couple hours.

I saw the problem as soon as I tried it. It was making two requests, of course being redirected by the server for authentication. The browser had the cookie - already authenticated. I simply turned off authentication for the source directory. Mime types from the server were perfectly fine. I did have another strange issue during troubleshooting that led me off path, but I'm not going to backtrack. I figured out the problem.

These are secure images though. I suppose I'll host them elsewhere under HTTP authentication and provide the credentials to Prince.

Prince is awesome.
mikeday
Right, cookie-based authentication with HTML login screens can be a bit tricky for automated tools to navigate! :)