簡體   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