How to write png file to target directory from client side by flask


I want to write to file from request.form["file"] but I can't do it.

My contact.html is here.

Client side code is like this...

<form action="contact" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="submit">

Server side is like this

filestorage = request.files["file"]

print type(_file) #-> <FileStorage: u"__proto.png" ("img/png")>

# I tried below this , but it doesn't work.

f = open("tmp.png","wb")

I want to write this which is png file to uploaded file somewhere. Do you have any idea?

Thanks in advance.

4/21/2013 3:23:44 PM

You have the save() method of the FileStorage object, that lets you save the file content to disk:'/path/to/your/file')

Flask Documentation:

A useful tutorial:

4/21/2013 4:06:27 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow