python - Django file uploading -
i need have ability upload files on server before uploading verify file whether file , image or script called image.jpeg. i'm using library called python-magic
import magic attachment = request.files['file'].read() m = magic.open(magic.magic_mime_type) m.load() ft = m.buffer(attachment) m.close()
its working fine me. should read whole file?
attachment = request.files['file'].read()
i think bad idea question how header of file weight? can read couple bytes , verify files mime-type.
you first guess mimetype using mimetype module suggested here. if ok guess, upload file webserver. in case access file afterwards, can entire check source provided, have read file anyway.
Comments
Post a Comment