简体   繁体   English

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

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

I have my REST application. 我有我的REST应用程序。

Client side -> Angular 5. 客户端-> Angular 5。

Server side -> python (using cherrypy). 服务器端-> python(使用cherrypy)。

Database -> SQL Server. 数据库-> SQL Server。

Database screen: enter image description here 数据库屏幕: 在此处输入图像描述

I want to click button and download a file to my computer. 我想单击按钮并将文件下载到我的计算机。 What is the best way to download this file from database? 从数据库下载此文件的最佳方法是什么?

Python: 蟒蛇:

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)  

I return this to client, but i know this is not correct. 我将此退还给客户,但我知道这是不正确的。 It was my first idea. 这是我的第一个主意。

Angular: 角度:

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;
  });

} }

Now I am trying to convert somehow this data to Blob and save as pdf. 现在,我正尝试将这些数据转换为Blob并另存为pdf。 I guesse is not correct so I decided to write here for help. 我猜是不正确的,所以我决定在这里写信寻求帮助。 Thanks! 谢谢!

Looks like you have the data in your db already as binary. 看起来您的数据库中的数据已经是二进制数据了。

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"]

Ps. 附言 I'm a django guy. 我是Django的家伙。 My cherrypi-foo is not very strong 我的cherrypi-foo不是很结实

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

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