2

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.

4

1 に答える 1

3

実際に問題を発見しました。ServeFile呼び出しの前にコンテンツ タイプを指定する必要があります。

  AResponseInfo.ContentType := 'image/jpeg';
  AResponseInfo.ServeFile(AContext,rootpath+ARequestInfo.document);
于 2013-05-29T14:12:59.517 に答える