Skip to content

Instantly share code, notes, and snippets.

@jpadilla
Last active August 29, 2015 14:08
Show Gist options
  • Save jpadilla/50dea4ca154f7f475981 to your computer and use it in GitHub Desktop.
Save jpadilla/50dea4ca154f7f475981 to your computer and use it in GitHub Desktop.
// 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
}
});
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