我在StackOverflow上的第一個問題。 。 。如何使用Python從Google App Engine顯示pdf blob
在使用python的Google App Engine應用程序中,我試圖在頁面上用html顯示一個小的pdf圖像。
我有一個小班級,這樣寫的:
class modelReport(db.Model):
Applicant = db.StringProperty()
Reportblob = db.BlobProperty()
的小型形狀用於將圖像上傳和圖像提交到以下處理:
class UploadResults(webapp.RequestHandler):
def post(self):
m = modelReport()
m.Applicant = self.request.get("txtApplicantName")
Reportblob = self.request.get("file")
m.Reportblob = db.Blob(Reportblob)
m.put()
我使用以下代碼顯示申請人的圖像和名稱:
class RetrieveResults(webapp.RequestHandler):
def get(self):
self.response.out.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="em">
<head>
<meta http-equiv="Content-Type" content="application/pdf" />
<title>Results Page</title>
</head>
<body>
''')
reports = db.GqlQuery('SELECT * FROM modelReport')
for report in reports:
self.response.out.write('</p><b>%s</b> report is:' % report.Applicant)
self.response.out.write("<div><img src='img?img_id=%s'></img>" % report.key())
self.response.out.write('''
</body></html>
''')
當使用開發服務器Datastore Viewer,我可以看到列出Key,Write Ops,ID,Key Name,Applicant和Reportblob的新「modelReport」實體。
問題是輸出列表申請人,然後顯示一個小的藍色框與「?」在中間像它找不到圖像文件。 。 。而且,開發服務器日誌控制檯顯示404錯誤:
INFO..."GET /retrieve_results/all_results HTTP/1.1" 200 -
INFO..."GET /retrieve_results/img?img_id=ag...Aww HTTP/1.1" 404 -
INFO..."GET /retrieve_results/img?img_id=ag...BQw HTTP/1.1" 404 -
INFO..."GET /retrieve_results/img?img_id=ag...Bgw HTTP/1.1" 404 -
我想了一會兒,我可期運用錯誤的「內容類型」頭,但使用Apache Web服務器類似的代碼顯示文字和圖片就好了。
似乎我可能會使空Blobstore屬性「Reportblob」,但我不知道如何驗證或調試。
任何或所有幫助修復GAE代碼將不勝感激。
您沒有使用Blob存儲區,你只是存儲內的一個blob實體。 – 2012-08-08 06:10:55
您應該發佈/ retrieve_results處理程序代碼。 – 2012-08-08 06:12:05
並歡迎堆棧溢出。 – 2012-08-08 06:12:33