I'm trying to save a .zip file received from an endpoint, but first check the contents of the .zip.
If I do:
import zipfile
from Flask import request
file = request.files["file"]
zf = zipfile.ZipFile(file, "r")
// some operation to check zf
file.save("path/to/save/file")
The saved file is empty. However, removing the construction of the ZipFile object, the file saved is not empty. Any advice on why this is the case?
Wanted to post the solution I found.
Adding
file.stream.seek(0)
to move the file pointer back to the beginning, before
file.save("path/to/save/file")
solves it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.