Last active
August 29, 2015 14:08
-
-
Save jpadilla/50dea4ca154f7f475981 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// https://example.com/index.html | |
$('#fileupload').fileupload({ | |
url: 'https://apiexample.com/upload/image/', | |
dataType: 'text', | |
paramName: 'file', | |
redirect: 'https://example.com/result.html?%s', | |
add: function (event, data) { | |
// Start upload | |
data.submit(); | |
}, | |
done: function (event, data) { | |
// Successful upload. Parse JSON text response | |
var result = $.parseJSON(data.result); | |
}, | |
fail: function (event, data) { | |
// Failed upload | |
} | |
}); |
This file contains hidden or 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
def post(self): | |
if (self.request.get('_method') == 'DELETE'): | |
return self.delete() | |
result = {'files': self.handle_upload()} | |
s = json.dumps(result, separators=(',', ':')) | |
redirect = self.request.get('redirect') | |
if redirect: | |
return self.redirect(str( | |
redirect.replace('%s', urllib.quote(s, ''), 1) | |
)) | |
if 'application/json' in self.request.headers.get('Accept'): | |
self.response.headers['Content-Type'] = 'application/json' | |
self.response.write(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment