add content-disposition for download urls

This commit is contained in:
j 2011-08-11 22:10:06 +02:00
parent fa55fd7af2
commit 36ce63477b
2 changed files with 6 additions and 3 deletions

View file

@ -16,7 +16,7 @@ urlpatterns = patterns("item.views",
(r'^(?P<id>[A-Z0-9].+)/(?P<profile>\d+p)(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', 'video'), (r'^(?P<id>[A-Z0-9].+)/(?P<profile>\d+p)(?P<index>\d*)\.(?P<format>webm|ogv|mp4)$', 'video'),
#torrent #torrent
(r'^(?P<id>[A-Z0-9][A-Za-z0-9]+)/torrent/(?P<filename>.+?)$', 'torrent'), (r'^(?P<id>[A-Z0-9][A-Za-z0-9]+)/torrent/(?P<filename>.*?)$', 'torrent'),
#icon #icon
(r'^(?P<id>[A-Z0-9].+)/icon(?P<size>\d*)\.jpg$', 'icon'), (r'^(?P<id>[A-Z0-9].+)/icon(?P<size>\d*)\.jpg$', 'icon'),

View file

@ -624,14 +624,17 @@ def torrent(request, id, filename=None):
response = HttpFileResponse(item.torrent.path, response = HttpFileResponse(item.torrent.path,
content_type='application/x-bittorrent') content_type='application/x-bittorrent')
filename = "%s.torrent" % item.get('title') filename = "%s.torrent" % item.get('title')
response['Content-Disposition'] = 'attachment; filename="%s"' % filename response['Content-Disposition'] = 'attachment; filename="%s"' % filename.encode('utf-8')
return response return response
while filename.startswith('/'): while filename.startswith('/'):
filename = filename[1:] filename = filename[1:]
filename = filename.replace('/../', '/') filename = filename.replace('/../', '/')
filename = item.path('torrent/%s' % filename) filename = item.path('torrent/%s' % filename)
filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename)) filename = os.path.abspath(os.path.join(settings.MEDIA_ROOT, filename))
return HttpFileResponse(filename) response = HttpFileResponse(filename)
response['Content-Disposition'] = 'attachment; filename="%s"' % \
os.path.basename(filename.encode('utf-8'))
return response
def video(request, id, profile, index=None, format=None): def video(request, id, profile, index=None, format=None):
print id, profile, index, format print id, profile, index, format