从SQL Server导出Python Blob

时间:2019-06-20 20:34:33

标签: python sql-server blob pyodbc

我在SQL Server中有一个表,该表的varbinary(max)列包含文件Blob。我正在使用Python和pyodbc导出这些文件,如下所示:

[
  {
    "RouteID": "r1",
    "Message": "Test2",
    "CreatedDate": "2019-06-20T14:33:27",
    "CreatedBy": "j","Replys": [
      {
        "RouteID": "r1",
        "Message": "reply1",
        "CreatedDate": "2019-06-20T14:33:54",
        "CreatedBy": "j"
      },
      {
        "RouteID": "r1",
        "Message": "reply2",
        "CreatedDate": "2019-06-20T14:34:04",
        "CreatedBy": "j"
      }
    ]
  },
  {
    "RouteID": "r1",
    "Message": "Test",
    "CreatedDate": "2019-06-20T14:33:21",
    "CreatedBy": "j","Replys": [
      {
        "RouteID": "r1",
        "Message": "reply3",
        "CreatedDate": "2019-06-20T14:34:11",
        "CreatedBy": "j"
      }
    ]
  }
]

这适用于文本文件,但所有其他文件类型(例如pdf,xlsx等)均已损坏。在记事本中打开导出的文件显示与在SQL Server中将该列强制转换为varchar相同的字符。

我该如何补救?

0 个答案:

没有答案