[Python-de] File Upload + mimetools/mimetypes ??
Gerhard Häring
haering_python at gmx.de
Wed Jul 17 14:35:42 EDT 2002
Hi!
* Matthias Braun <braun at die-optiker.com> [2002-07-17 09:24 +0200]:
> [...] Nun arbeite ich gerade an einem Projekt (Python), im welchen ich
> ein File Upload (Client auf Server) einbauen soll.
Um welche Art Upload soll es sich denn handeln? Einen HTTP-Upload über
von einer HTML-Seite aus? Hier ist ein einfaches Beispiel dazu, nur
abgetippt von http://www.python.org/doc/essays/ppt/sd99east/sld058.htm:
#!/usr/bin/env python
import cgi
form = cgi.FieldStorage()
print "Content-Type: text/html\n"
if form.has_key("filename"):
item = form["filename"]
if item.file:
data = item.file.read()
# Hier irgendwas mit den gelesenen Daten machen, z. B. in ein
# bestimmtes Verzeichnis speichern
print "<html><body>Dateupload erfolgreich.</body></html>"
else:
# Jemand wollte bescheissen ;-)
else:
# Keine Datei angegeben.
Das HTML dazu:
<html>
<body>
<form action="/cgi-bin/upload.py" method="POST" enctype="multipart/form-data">
<input type="file" name="filename">
<input type="submit">
</form>
</body>
</html>
Es gibt noch andere Möglichkeiten, ohne Webbrowser eine Datei auf einen
Webserver zu bringen. HTTP PUT oder einfach FTP.
Was war dein Problem mit Mimetypes?
Gerhard
--
This sig powered by Python!
Außentemperatur in München: 19.6 °C Wind: 3.6 m/s
More information about the Python-de
mailing list