Posielanie obrázkov z Web Application
Vytvor novú webovú aplikáciu (File - New - Web Server Application, ISAPI DLL) a pridaj novú Action. Nastav PathInfo na ‘/motorcycle.jpg’ a v OnAction udalosti pridaj nasledujúci kód.
procedure TWebModMain.WebModMainwbactnGetJpegAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); // Helper function to get the current directory the DLL is in function GetDllDir: string; begin SetLength(Result, MAX_PATH+1); // Add 1 for the null character GetModuleFileName(hInstance, PChar(Result), MAX_PATH+1); SetLength(Result, Length(PChar(Result))); Result := ExtractFilePath(Result); end; var FileStream: TFileStream; begin // This demonstrates returning a Jpeg file from a file on the hard drive. try FileStream := TFileStream.Create(GetDllDir + 'motorcycle.jpg', fmOpenRead); // Note that the file 'motorycle.jpg' must be in the same // directory as this DLL. FileStream.Position := 0; // Go to the start of the stream Response.ContentStream := FileStream; Response.ContentType := 'image/jpeg'; Response.SendResponse; // Notice that the stream is not freed (it shouldn't be!) except // Catch all exceptions and show a custom message on E: Exception do Response.Content := '<html><body>An error occurred ' + E.ClassName + ': ' + E.Message + '</body></html>'; end; end;