def download(self, request, **kwargs):
'''
example use:
http://.../fileservice/download/med.mp4/
or
http://.../fileservice/med.mp4/download/
'''
# method check to avoid bad requests
self.method_check(request, allowed=['get'])
# Must be done otherwise endpoint will be wide open
self.is_authenticated(request)
response = None
file_item_name = kwargs.get('name', None)
if file_item_name:
filename_absolute = helpers.get_filename_absolute(file_item_name)
if os.path.isfile(filename_absolute):
response = serve(request, os.path.basename(filename_absolute), os.path.dirname(filename_absolute))
response['Content-Disposition'] = 'attachment; filename="{}"'.format(
os.path.basename(filename_absolute))
if not response:
response = self.create_response(request=request, data={}, response_class=HttpNotFound)
return response
评论列表
文章目录