Created
May 21, 2013 11:49
-
-
Save 4toblerone/5619259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#upload_btn").click(function(){ | |
var fileIn = $("#fileToUpload")[0]; | |
if (fileIn.files === undefined || fileIn.files.length == 0) { | |
alert("Please select a file"); | |
return; | |
} | |
var file = fileIn.files[0]; | |
var fotka = new FormData() | |
fotka.append('file' , file) | |
alert(file.type); | |
//Show the progress bar | |
$("#progressbar").show(); | |
$.ajax({ | |
url: "/proba", | |
type: "POST", | |
data: fotka, | |
processData: false, | |
contentType: file.type, | |
success: function(){ | |
$("#progressbar").hide();}, | |
error: function(){alert("Failed");}, | |
xhr: function() { | |
myXhr = $.ajaxSettings.xhr(); | |
if(myXhr.upload){ | |
myXhr.upload.addEventListener('progress',showProgress, false); | |
} else { | |
console.log("Upload progress is not supported."); | |
} | |
return myXhr; | |
} | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/proba' , methods= ['POST']) | |
def proba(): | |
print request.environ | |
print request.environ['wsgi.input'] | |
"""{'wsgi.multiprocess': False, 'HTTP_COOKIE': 'session="1FXRQXWcbS5MIp4rSxwZNzV37P | |
o=?_id=Uyd7aFx4YzVceGYyXHgxZVx4YmN5XHhhYVBsXHgwM1x4OWZjXHg5NFRceDkyJwpwMQou&csrf | |
=UyczNmMzZDU4Mzk3ZDA1YTFmN2U3NzljMDNmZDRmOWIzYzNmNTNiMjk1JwpwMQou"', 'SERVER_SOF | |
TWARE': 'Werkzeug/0.8.3', 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'POST', 'PATH_INF | |
O': '/proba', 'HTTP_ORIGIN': 'http://localhost:5000', 'SERVER_PROTOCOL': 'HTTP/1 | |
.1', 'QUERY_STRING': '', 'werkzeug.server.shutdown': <function shutdown_server a | |
t 0x038A1870>, 'CONTENT_LENGTH': '387135', 'HTTP_ACCEPT_CHARSET': 'windows-1251, | |
utf-8;q=0.7,*;q=0.3', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) Ap | |
pleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31', 'HTTP_C | |
ONNECTION': 'keep-alive', 'HTTP_REFERER': 'http://localhost:5000/admin', 'SERVER | |
_NAME': '127.0.0.1', 'REMOTE_PORT': 53994, 'wsgi.url_scheme': 'http', 'SERVER_PO | |
RT': '5000', 'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest', 'werkzeug.request': <Req | |
uest 'http://localhost:5000/proba' [POST]>, 'wsgi.input': <socket._fileobject ob | |
ject at 0x038A17B0>, 'HTTP_HOST': 'localhost:5000', 'wsgi.multithread': False, ' | |
HTTP_ACCEPT': '*/*', 'wsgi.version': (1, 0), 'wsgi.run_once': False, 'wsgi.error | |
s': <open file '<stderr>', mode 'w' at 0x021450D0>, 'REMOTE_ADDR': '127.0.0.1', | |
'HTTP_ACCEPT_LANGUAGE': 'sr-RS,sr;q=0.8,en-US;q=0.6,en;q=0.4', 'CONTENT_TYPE': ' | |
image/jpeg', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch'} | |
<socket._fileobject object at 0x038A17B0>""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment