1
如何發送文件作爲對使用瓶框架的Python中的HTTP請求的答案?用Python框架通過http發送文件與瓶框架
上傳此代碼的工作對我來說:
@route('/upload', method='POST')
def do_upload():
category = request.forms.get('category')
upload = request.files.get('upload')
name, ext = os.path.splitext(upload.raw_filename)
if ext not in ('.png','.jpg','.jpeg'):
return 'File extension not allowed.'
save_path = category
upload.raw_filename = "hoho" + ext
upload.save(save_path) # appends upload.filename automatically
return 'OK'