api.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:exchange 作者: boundlessgeo 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号