如何在Django中从数据库中的blob字段下载数据?

5

我有一个表格,其中包含一个BLOB列,其中包含一些数据,如何在Django中下载BLOB内容? 我尝试了这里提供的解决方案,但对我没有用。


你想要它以什么格式? - user1428660
1个回答

6
def download_blob(request, id):

    contents = BlobModel.objects.get(id=id).blob_field

    response = HttpResponse(contents)
    response['Content-Disposition'] = 'attachment; filename=blob.bin'
    return response

1
非常好用!谢谢!我已经搜索了两天! - user2137817

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接