I have looked into the source and documentation of werkzeug, it's nowhere specified what mode it's opened. Since the default open mode for normal file is text mode, it brings me the question. Earlier, I had a problem to save the data=storage.read() into LargeBinary type in sqlalchemy, with an error saying: can't convert unicode to byte type.
Yes, the files are opened in binary mode. See the default_stream_factory()
function source:
def default_stream_factory(total_content_length, filename, content_type, content_length=None): """The stream factory that is used per default.""" if total_content_length > 1024 * 500: return TemporaryFile('wb+') return BytesIO()
So either you get a TemporaryFile()
object opened in wb+
mode (write and read, binary), or an in-memory BytesIO
object.