Invalid mode: wb when trying to upload file using Django and AJAX
So I'm trying to use an ajax file upload form with Django and 开发者_运维知识库running into an issue with FileIO. Specifically,
with BufferedWriter( FileIO( filename, "wb" ) ) as dest:
results in
ValueError: invalid mode: wb
I'm running Python 2.6/Django 1.3 locally on OSX 10.6.7. I tried chmod +X to the directory I'm targeting with the filename. Any idea what I'm missing? Thanks.
http://docs.python.org/release/2.6.6/library/io.html#raw-file-i-o
FileIO represents a file containing bytes data. It implements the RawIOBase interface (and therefore the IOBase interface, too).
The mode can be 'r', 'w' or 'a' for reading (default), writing, or appending. The file will be created if it doesn’t exist when opened for writing or appending; it will be truncated when opened for writing. Add a '+' to the mode to allow simultaneous reading and writing.
The "mode" is what you're trying to set is where you use "rb," which in the documentation isn't a valid mode. Either way, the fact that it's reading in raw data from a file seems to indicate that FileIO is set in binary mode by default--so the "b" seems unnecessary to me.
精彩评论