繁体   English   中英

如何使用python(服务器)和Angular(客户端)从SQL Server发送pdf数据并保存

[英]How to send pdf data and save from SQL Server using python(server) and Angular (client)

我有我的REST应用程序。

客户端-> Angular 5。

服务器端-> python(使用cherrypy)。

数据库-> SQL Server。

数据库屏幕: 在此处输入图像描述

我想单击按钮并将文件下载到我的计算机。 从数据库下载此文件的最佳方法是什么?

蟒蛇:

with CDN_XL:
        CDN_XL.executeWithParams("""SELECT DAB_Dane FROM CDN.DaneBinarne, CDN.DaneObiekty WHERE DAB_ID = DAO_DABId AND DAB_ID = %s""", (download_id))
        CDN_XL.conn.commit()
        types = CDN_XL.cur.fetchall()
        information_json = []
        if types is not None and len(types) > 0:
            for typ in types:
              information_json.append({"data": str(typ["DAB_Dane"])})

            output_json = {"files":information_json}
            return json.dumps(output_json, ensure_ascii=False)  

我将此退还给客户,但我知道这是不正确的。 这是我的第一个主意。

角度:

public downloadAttachments(id, idAttachment) {
  const requestUrl = this.firmListBaseUrl + id + '/ZALACZNIKI/' + idAttachment + '/' + idAttachment;
  return this.http.get(requestUrl, { headers: this.sharedServicesService.prepareAuthHeaders() })
  .map(res => {
    return res.json().files;
  });

}

现在,我正尝试将这些数据转换为Blob并另存为pdf。 我猜是不正确的,所以我决定在这里写信寻求帮助。 谢谢!

看起来您的数据库中的数据已经是二进制数据了。

with CDN_XL:
        CDN_XL.executeWithParams("""SELECT DAB_Dane FROM CDN.DaneBinarne, CDN.DaneObiekty WHERE DAB_ID = DAO_DABId AND DAB_ID = %s""", (download_id))
        CDN_XL.conn.commit()
        pdf_bin = CDN_XL.cur.fetchone() 

        cherrypy.response.headers['Content-Type'] = 'application/pdf'
        cherrypy.response.headers['Content-Disposition'] = 'inline;filename="report.pdf"'
        return pdf_bin["DAB_Dane"]

附言 我是Django的家伙。 我的cherrypi-foo不是很结实

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM