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



我有我的REST应用程序。

客户端 -> 角度 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"]

附言。我是一个姜戈人。我的樱桃不是很强

最新更新