X~~X~~ 2022-10-11 10:29 采纳率: 34.2%
浏览 68
已结题

从数据库可以获取多个链接下载文件前端是vue,现在这样写下载一个return就结束了,后面都来不及下载

从数据库可以获取多个链接下载文件前端是vue,现在这样写下载一个return就结束了,后面都来不及下载

def post(self, request):
    '''下载文件'''
    # 获取请求体中原始的JSON数据
    json_str = request.body
    # 使用json模块将原始的JSON数据转字典
    json_dict = json.loads(json_str)
    masterorder_id = json_dict.get('masterorder_id')
    try:
        obj_master = MasterOrder.objects.get(id=masterorder_id)
        if eval(obj_master.filepath):
            for path in eval(obj_master.filepath):
                filename = os.path.basename(path)
                file = open(path, 'rb')
                response = FileResponse(file)
                response['Content-Type'] = 'application/octet-stream'
                response['Access-Control-Expose-Headers'] = "Content-Disposition, Content-Type"

                response['Content-Disposition'] = 'attachment;filename={}'.format(filename)

                return response
        else:
            return JsonResponse(
                {'code': 1, 'error': "File does not exist"})
    except Exception as e:
        return JsonResponse(
            {'code': 1, 'error': "Failed to submit text, the specific reason:" + str(e)})
  • 写回答

3条回答 默认 最新

  • honestman_ 2022-10-11 10:38
    关注

    定义一个列表,把下载的内容放到列表列,最后返回列表

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月11日
  • 赞助了问题酬金1元 10月11日
  • 赞助了问题酬金1元 10月11日
  • 赞助了问题酬金1元 10月11日
  • 展开全部