Skip to content

Commit

Permalink
Fix 670207: Change image url to query string argument for base64ing i…
Browse files Browse the repository at this point in the history
…mages
  • Loading branch information
Michael Kelly committed Jul 13, 2011
1 parent ee8a598 commit 6ff0923
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/homesnippets/urls.py
Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions apps/homesnippets/views.py
Expand Up @@ -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}),
Expand Down
2 changes: 1 addition & 1 deletion site_media/snippetBodyWidget.js
Expand Up @@ -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.');
Expand Down

0 comments on commit 6ff0923

Please sign in to comment.