tags:

views:

15

answers:

1

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.

+1  A: 

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)
THC4k