Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix 670207: Change image url to query string argument for base64ing i…

…mages
  • Loading branch information...
commit 6ff092398e084a0c2c5548f411d29f4cb3a95f06 1 parent ee8a598
Michael Kelly Osmose authored
2  apps/homesnippets/urls.py
View
@@ -16,7 +16,7 @@
'(?P<distribution>[^/]+)/(?P<distribution_version>[^/]+)/$',
'view_snippets', name='preview_snippets', kwargs={'preview': True}),
- url(r'^base64encode/(?P<url>.+)$', 'base64_encode', name='base64_encode'),
+ url(r'^base64encode$', 'base64_encode', name='base64_encode'),
url(r'^admin/bulk_date_change$', 'admin_bulk_date_change',
name='admin_bulk_date_change'),
url(r'^$', 'index', name='index'),
4 apps/homesnippets/views.py
View
@@ -82,11 +82,11 @@ def view_snippets(request, **kwargs):
def base64_encode(request, **kwargs):
"""Encode a remote image to base64, and output as JSON."""
- url = kwargs['url']
try:
+ url = request.GET['url']
img_file = urlopen(url)
base64_str = base64.encodestring(img_file.read())
- except (URLError, ValueError):
+ except (URLError, ValueError, KeyError):
raise Http404
return HttpResponse(json.dumps({'img': base64_str}),
2  site_media/snippetBodyWidget.js
View
@@ -40,7 +40,7 @@ jQuery(function($) {
function encodeIcon(icon_url, successCallback) {
// TODO: Support non-png images
$.ajax({
- url: '/base64encode/' + icon_url,
+ url: '/base64encode?url=' + encodeURIComponent(icon_url),
dataType: 'json',
error: function() {
alert('Error encoding icon. Please check that the icon URL points to a valid PNG image.');
Please sign in to comment.
Something went wrong with that request. Please try again.