Autor Beitrag
pigfacejoe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 11:52 
Hallo zusammen und Frohes Neues Jahr!
Ich will einen Download aus dem Internet starten, was ja auch soweit klappt. Allerdings möchte ich das File in einem Ordner ablegen, das Problem ist allerdings das ich im Quelltext schreibe, das beispielsweise der Pfad C:\test.exe ist, was mache ich nun aber , wenn die Datei mal eine .zip oder .jpg Datei ist?? Wie kann ich den Namen mit Endung der gedownloadeten Datei herausfinden mit der idhttp Komponente?

Vielen Dank für eure Antworten
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 17:07 
Geht das überhaupt mit idhttp? Weil ich finde nix im forum
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 07.01.07 17:11 
Na die weisste doch wenn Du die Datei anforderst www.bla.url/file.dat
Oder meinst Du ExtractFileExt

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 17:17 
ja aber wie komme ich an das ende? also die Datei soll ja dann in den Programmordner als
file.dat gespeichert werden , nicht aber als www.bla.url/file.dat, damit der PC auch weiss , um welche date es sich handelt (z.B .exe oda so). Nur weiss ich nicht, wie ich nur an das Ende komme, also den namen der datei. Gibts da nicht sowas wie Extractfilename() oder so bei idhttp?
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 07.01.07 17:29 
Bei IdHttp nicht aber in der SysUtils.
Ich will aber meinen man muss erst die Slashes erstezten.
Also:
ausblenden Delphi-Quelltext
1:
2:
sUrl:=StringReplace(sUrl, '/''\', [rfReplaceAll]);
showmessage(ExtractFileExt(sUrl));


Edit: Du kannst auch den MIME-Type abfragen. Dann weisst Du genau um welcheDateitypen es sich handelt musst aber dann die Ext wieder selber definieren.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function GetMIMEType(sFile: TFileName): String;
var
  MIMEMap: TIdMIMETable;
begin
  MIMEMap := TIdMIMETable.Create(True);
  Result := MIMEMap.GetFileMIMEType(sFile);
  MIMEMap.Free;
end;

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: So 07.01.07 17:36 
Sowas ist schnell geschrieben (sofern man die Sourcen hat^^):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function ExtractHTTPFileExt(const FileName: string): string;
var
  I: Integer;
begin
  I := LastDelimiter('./', FileName);
  if (I > 0and (FileName[I] = '.'then
    Result := Copy(FileName, I, MaxInt) else
    Result := '';
end;


Ungetestet, war aber nur eine Änderung (+ Prozedurname)

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 07.01.07 17:57 
Frage: wie lädst Du die Datei runter? Normalerweise gibt man den kompletten Dateinamen inklusive Extension an, also weißt Du doch um was für eine Datei es sich handelt. Dementsprechend wird der Filestream angelegt.
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 07.01.07 18:08 
es müsste aber auch irgenendwo im HTTP Header drinstehen.
und das wäre die beste Methode, da man ja auch z.b. mit PHP eine Art URL-Verschleierung machen kann.
Und wenn du dann z.b. von www.test.de/download.php?id=wasauchimmer eine Datei bekommst, dann heisst deine Datei auf der Festplatte download.php?id=wasauchimmer und du bekommst Probleme, weil ein ? in einem Dateinamen nicht erlaubt ist !

Also einfach mal in deine HTTP Header schauen !
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 07.01.07 18:13 
IdHTTP.Head ist eigentlich nur für HTML. Auch wenn das klappen würde, muß er doch den kompletten Dateinamen inklusieve Extension angeben und zwar ohne Wildcards, sonst bekommt er die schöne Meldung: Multiple Choices.
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 18:27 
Idhttp1.head gibts bei mir irgendwie nicht...
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 18:33 
Ah sry, gibts doch :oops:
leider funktioniert das hier nicht:
ausblenden Delphi-Quelltext
1:
Ziel:=ExtractFilePath(Paramstr(0))+idhttp1.head(edit1.Text);					

und ich bekomme folgende meldung:
[Fehler] Unit1.pas(65): Inkompatible Typen: 'String' und 'procedure, untyped pointer or untyped parameter'
[Fataler Fehler] Project1.dpr(5): Verwendete Unit 'Unit1.pas' kann nicht compiliert werden

Was liefert die Prozedur überhaupt?
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 07.01.07 18:49 
Und was soll das jetzt werden?
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 18:55 
ja , keine ahnung^^
einfach mal geschrieben, ich weiss ja nicht was ich sonst probieren soll^^
Das hier klappt nur bei Adressen wie afrrese.de/test.exe nicht aber bei 212.162.61.166/downl...1cfbd9df8a05d1e8.exe , wie matze schon geschrieben hatte, jetz wiess ich halt nicht weiter

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function ExtractHTTPFileExt(const FileName: string): string;
var
  I: Integer;
begin
  I := LastDelimiter('./', FileName);
  if (I > 0and (FileName[I] = '.'then
    Result := Copy(FileName, I, MaxInt) else
    Result := '';
end;
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 07.01.07 19:12 
Den kompletten Dateinamen kennst Du aber?
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 07.01.07 19:23 
So, kleines Testprogramm für Dich.
Einloggen, um Attachments anzusehen!
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 20:17 
Hi Andidreas!
Danke für das Programm , das macht mein Programm ja auch , allerdings ist mein Problem , dass wenn der nutzer, der den Pfad angibt, beispielsweise bei chip.de die Verknüpfung kopiert, ist das so ein link , wie matze geschrieben hat, dann geht das eben nicht. Anders klappt meins ja auch schon , allerdings eben nicht bei einem link, der so aussieht:
www.test.de/download.php?id=wasauchimmer (wie bei matze) . Und das ist ja gerade mein Problem!!
Trotzdem Danke , dass du dir die Mühe gemacht hast!
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 07.01.07 20:23 
Das dürfte ja wohl Absicht sein mit download.php?id= um eben einen direkten Download zuverhindern.
Siehe hier www.php4u.net/index.php?main=tut1 warum
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 20:33 
ja ber wie machens dann andere Download Manager? Die müssen ja wohl irgendwoher den direkten Link haben , um an den namen der datei ranzukommen und die dateiendung, oder nicht? Bei mir klappt ja der Download, Fortschritt, Geschwindigkeit usw perfekt, das einzige was schwierigkeiten macht ist das dumme speichern, weil ich eben nicht weiss , ob es sich um eine .exe, .jpg... datei handelt
Ausserdem würde ich gernen den Namen des herstellers beibehalten, also nicht irgendwie unter Download 1 , Download 2 usw speichern.


Zuletzt bearbeitet von pigfacejoe am So 07.01.07 20:44, insgesamt 1-mal bearbeitet
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 07.01.07 20:43 
Die senden das so, und bekommen die Datei. Da kann man wohl nur probieren. Hast Du zufällig so einen Link?
pigfacejoe Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: So 07.01.07 20:47 
Klar: 212.162.61.166/downl...43a8e1a54063e0b1.exe
also hier gehts z.b nicht un das ist (glaub ich) keine php?id= blabla Seite