开发者

In Python + Pylons, simple way to copy uploaded file to disk

开发者 https://www.devze.com 2023-01-19 07:41 出处:网络
How can I copy a posted file to disk? Can I do something like: file = \'/uploaded_开发者_开发百科files/test.txt\'

How can I copy a posted file to disk?

Can I do something like:

file = '/uploaded_开发者_开发百科files/test.txt'
shutil.copy2(request.POST['file'],file)

Thanks.


You do something like this:

tempfile = request.POST['file']
file_path = 'uploaded_files/' + tempfile.filename # for the original filename
permanent_file = open( file_path, 'wb')
shutil.copyfileobj(tempfile.file, permanent_file)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号