Autor Beitrag
FloFri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: Sa 22.02.03 16:42 
Hi!
Ich habe ein etwas kompliziertes Problem.
Ich benutze die Indy-HTTP-Server komponente für einen webserver. Jetzt mein Problem. Ich fange mit der Komponente die Angeforderten Dateien ab und führe gegebenfalls aktionen auf dem Webserver aus (Beispiel: ruft der benutzer die datei message.brs mit einem beliebigen Parameter auf, so wird das, was in dem Parameter steht als MessageBox am Server ausgegeben, so eine Art Remote Administration.). Jetzt mein Problem. Ich möchte, wenn ein Client die Datei getfile.brs mit einem parameter aufruft dem die Datei, welche im Parameter steht senden, anstatt der getfile.brs. Klappt auch ganz gut mit HTTP.ServeFile. Allerdings ist das Problem, das der Client die Datei nicht runtelädt/runterladen will, sondern diese als textdatei im browser anzeigt (auch exe). Wie kann ich das möglichst einfach beheben/umgehen.

Ich hoffe, man kann halbwegs verstehen, was ich meine :)

MfG
FloFri
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: Sa 22.02.03 18:31 
Hallo,

du musst vorher den Content-Type für die Datei festlegen.
Ich habe noch keine Standard-Prozedur dafür gefunden, deshalb habe ich mir eine Funktion gebastelt á la
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Function GetContentType(Extension: String):String;
begin
Result := 'text/plain';
If Extension = '.txt' then Result := 'text/plain';
If (Extension = '.tar') then Result := 'application/x-tar';
If (Extension = '.ps') then Result := 'application/postscript';
If (Extension = '.doc') then Result := 'application/msword';
If (Extension = '.pdf') then Result := 'application/zip';
If (Extension = '.jpe') or (Extension = '.jpg')or (Extension = '.jpeg') then Result := 'image/jpeg';
If (Extension = '.bmp') then Result := 'image/ms-bmp';
If (Extension = '.gif') then Result := 'image/gif';
If (Extension = '.tif') or (Extension = '.tiff') then Result := 'image/tiff';
If (Extension = '.xbm') then Result := 'image/x-bmp';
If (Extension = '.mpg') or (Extension = '.mpe') or (Extension = '.mpeg') then Result := 'video/mpeg';
If (Extension = '.avi') or (Extension = '.wmv') then Result := 'video/x-msvideo';
If (Extension = '.mov') or (Extension = '.qt') then Result := 'video/quicktime';
If (Extension = '.au') or (Extension = '.snd') then Result := 'audio/basic';
If (Extension = '.wav') then Result := 'audio/x-wav';
If (Extension = '.html') or (Extension = '.htm')or (Extension = '.shtml')or (Extension = '.sht') then Result := 'text/html';
If (Extension = '.wrl') then Result := 'x-world/x-vrml';
end;


Danach schaust du, welche Endung (Variable X) deine Datei hat, die du verschicken willst und rufst die Funktion mit:
ausblenden Quelltext
1:
2:
idHTTPServer1.ResponseInfo.ContentType := GetContentType(X);
idHTTPServer1.ServeFile(AThread,ResponseInfo,x);


So habe ich es gelöst. Funktioniert prima.

_________________
If accidentally read, induce vomitting.
FloFri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: Sa 22.02.03 20:00 
Gibt es noch eine "unbekannt" extension, die den client auch zum runterladen bringt?
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: Sa 22.02.03 20:09 
Ist mir nicht bekannt.
Du kannst ja für eine unbekannte Dateiendung irgendwas einsetzen.

Siehe Anfang der Funktion :
ausblenden Quelltext
1:
Result := (irgendein Format);					


Für eine Übersicht aller Formate suche mal mit Google nach MIME-Typen.
FloFri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: Sa 22.02.03 20:55 
Danke!
FloFri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: Sa 22.02.03 21:10 
Noch eine Frage, das mit dem Download geht jetzt, aber der benutzt immer als standart den namen getfile.brs (der wird die tatsächliche Datei als parameter übergeben) und nicht den der tatsächlichen Datei. Kann man das auch noch anpassen?
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: So 23.02.03 03:02 
Hast du denn die Parameter ausgelesen?

Du musst dann doch nur noch die Datei, die als Parameter übergeben wird senden. Vorher zerpflückst es, um die Dateiendung herauszubekommen und durch die Funktion zu schicken.
FloFri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: So 23.02.03 11:45 
Hab ich ja, der downloadet auch die richtige datei, aber mit falschem namen als vorgabe beim download. Da benutzt er den namen der datei, der die richtige datei als parameter übergeben wurde.
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: So 23.02.03 17:56 
Dann füge mal, nachdem du die Datei im Parameter ausgelesen hast, folgendes in deine OnCommandGet-Prozedur hinzu:

ausblenden Quelltext
1:
ResponseInfo.Redirect([ Hier den Dateinamen rein ]);					


Das sollte funktionieren.

_________________
If accidentally read, induce vomitting.
FloFri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: So 23.02.03 19:18 
Irgendwie funzt jetzt der content typ nicht mehr :(
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: So 23.02.03 19:59 
Was funktioniert denn nicht mehr?
FloFri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97



BeitragVerfasst: So 23.02.03 23:25 
Jetzt zeigt der die datei wieder im browser an, egal, was für ein content typ.
Ex0rzist
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 550

Win XP Prof.
Mandrake 10.0

D6
BeitragVerfasst: Mo 24.02.03 15:19 
Hast du auch überprüft, ob die "Content-Type"-Funktion überhaupt mit der Datei durchlaufen wird?
Oder taucht die Endung der Datei nicht in der Funktion auf? Weil dann ist es, wenn du meine Funktion übernommen hast, standardmäßig für unbekannte Datei-Endungen auf "text/plain" gesetzt.

_________________
If accidentally read, induce vomitting.