0

I'm trying to do some testing in html5 uploading files,here is the simple html codes:

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

I use python -m SimpleHTTPServer to test this section the problem is that I DON'T know how to write the handlecode file to handle the http request,

the handlecode file only save the file in the upload floder,no more complicated tasks

Although I don'k know whether testing in this way is right or not

Can someone give some hints or offer me the right way to test ,Thank you all very much!

1 Answer 1

5

Use bottle:

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.