Garrafa Python - Como fazer upload de arquivos de mídia sem DOSing do servidor
Eu estava usando a resposta deessa questão e viu o comentário:
raw = data.file.read() # This is dangerous for big files
Como faço para enviar o arquivo sem fazer isso? Meu código até agora é:
@bottle.route('/uploadLO', method='POST')
def upload_lo():
upload_dir = get_upload_dir_path()
files = bottle.request.files
print files, type(files)
if(files is not None):
file = files.file
print file.filename, type(file)
target_path = get_next_file_name(os.path.join(upload_dir, file.filename))
print target_path
shutil.copy2(file.read(), target_path) #does not work. Tried it as a replacement for php's move_uploaded_file
return None
o que fornece esta saída:
127.0.0.1 - - [03/Apr/2014 09:29:37] "POST /uploadLO HTTP/1.1" 500 1418
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\bottle.py", line 862, in _handle
return route.call(**args)
File "C:\Python27\lib\site-packages\bottle.py", line 1727, in wrapper
rv = callback(*a, **ka)
File "C:\dev\project\src\mappings.py", line 83, in upload_lo
shutil.copy2(file.read(), target_path)
AttributeError: 'FileUpload' object has no attribute 'read'
Estou usando o python bottle v.12, dropzone.min.js e mongodb. Eu também estou usando este tutorial:
http://www.startutorial.com/articles/view/how-to-build-a-file-upload-form-using-dropzonejs-and-php