[英]how to simply handle the request with python
我正在嘗試在html5上傳文件中進行一些測試,這是簡單的html代碼:
var fileInput=document.getElementById("the-file") fileInput.addEventListener('change',function(e){ var file=e.target.files[0] var xhr=new XMLHttpRequest() xhr.open('post','upload/handlecode',true) xhr.send(file) }
我使用python -m SimpleHTTPServer
測試此部分的問題是我不知道如何編寫handlecode文件來處理http請求,
handlecode文件僅將文件保存在上載文件中,沒有其他復雜的任務
雖然我不知道以這種方式進行測試是否正確
有人可以給我一些提示或提供給我正確的測試方法,謝謝大家!
使用瓶 :
from bottle import request, route, run
@route('/upload', method='POST')
def do_upload():
data = request.files.get('data')
raw = data.file.read()
filename = data.filename
return "You uploaded %s (%d bytes)." % (filename, len(raw))
run(host='localhost', port=8080)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.