Get mime type and filename without path in python
Hi, I want to allow uploading files from my website and put it in a database. My short script works: if myfile and myfile.filename != '': container.dbUpdateFile (id=str (id_ds), myfile=myfile.read ()) Now I want to put the mimetype in the database put how can I get the mimetype? I try: import mimetypes guess_type(myfile.filename) but I got an the error "*You are not authorized to access this resource".* What's wrong? I also want to put the filename in my database, but the Internet Explorer gives me the filename with path. Is there a funtionc to get the filename without path? Thanks, Patrick
Patrick Ulmer wrote at 2004-9-17 09:43 +0200:
I want to allow uploading files from my website and put it in a database. My short script works:
if myfile and myfile.filename != '': container.dbUpdateFile (id=str (id_ds), myfile=myfile.read ())
Now I want to put the mimetype in the database put how can I get the mimetype?
There is a "guess_mimetype" (or similarly spelled) that does this job for "OFS.Image". See there, how it is used. You may need an External Method (or special security declaration see "PythonScripts.README") to overcome security restrictions. -- Dieter
Hi,
I want to allow uploading files from my website and put it in a database. My short script works:
if myfile and myfile.filename != '': container.dbUpdateFile (id=str (id_ds), myfile=myfile.read ())
Now I want to put the mimetype in the database put how can I get the mimetype?
I try:
import mimetypes guess_type(myfile.filename)
but I got an the error "*You are not authorized to access this resource".*
I solved my little Problem by using an External Method and the Python-Package mimetypes. Thanks, Patrick
participants (2)
-
Dieter Maurer -
Patrick Ulmer