Reputation: 6364
I have written a TIdHTTPServer web server. Indy version is 10, Delphi is 2007.
I use the following code to send back jpeg, gif, png, etc, files:
AResponseInfo.ServeFile(AContext,rootpath+ARequestInfo.document);
AResponseInfo.ContentType := 'image/jpeg';
AResponseInfo.ContentType := GetMimeTypeFromFile('.'+ExtractFileDir(rootpath+ARequestInfo.document));
The images display properly in all browsers. But I see (via console in Chrome) they are being returned as MIME type: text/html. I have tried both image/jpeg and the GetMIMTypeFromFile methods and both yield text/html.
Is there another call I have to make? I saw in other threads calls to the AResponseInfo.WriteHeader function. But when added it raises an exception the header is being written twice.
Upvotes: 2
Views: 2478
Reputation: 6364
Actually found the problem. Need to specify the Content Type BEFORE the ServeFile call.
AResponseInfo.ContentType := 'image/jpeg';
AResponseInfo.ServeFile(AContext,rootpath+ARequestInfo.document);
Upvotes: 3