我做應用程序引擎的文檔中指定的,但我不能讓Blob存儲區工作的一切。也許你們中的一些人可以發現我做錯了什麼。當我點擊提交按鈕如何使用Python App Engine中的BlobStore上傳文件?
這種URL的是出現在地址欄和一個空白頁是在我的面前。
http://localhost:8080/_ah/upload/agltb2JpbHNvcnVyGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxg9DA
有沒有人有一個建議?
這是我的處理程序:
class MainHandler(webapp.RequestHandler):
def get(self):
years = Years.all().order("Year")
months = Months.all().order("SortNumber")
upload_url = blobstore.create_upload_url('/imidergi/upload')
content = {
'upload': upload_url,
'yearList':years,
'monthList':months,
}
render_template(self, 'imidergi.html', content)
class AddDergi(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
# 'file' is file upload field in the form
upload_files = self.get_uploads('file')
blob_info = upload_files[0]
dergi = Dergiler()
dergi.Year = self.request.get("yil")
dergi.Month = self.request.get("ay")
dergi.DergiPDF = str(blob_info.key())
dergi.Name = self.request.get("isim")
dergi.Image = self.request.get("resim")
dergi.put()
self.response.out.write(dergi.Name)
這是呈現表單的HTML。
<form action="{{ upload }}" method="post" id="dergiform" enctype="multipart/form-data">
{{ upload }}
<label>Yil:</label><select name="yil">
{% for year in yearList %}
<option value="{{ year.Year }}">{{ year.Year }}</option>
{% endfor %}
</select><br/>
<label>Ay:</label><select name="ay">
{% for month in monthList %}
<option value="{{ month.Name }}">{{ month.Name }}</option>
{% endfor %}
</select><br/>
<label>Isim: </label><input type='text' id="isim" name="isim"/><br/>
<label>Dergi: </label><input type='file' id="file" name="file"/><br/>
<label>Resim: </label><input type='file' id="resim" name="resim"/><br/>
<label></label><input type='submit' value='Ekle'/>
</form>
你爲什麼存儲Blob鍵爲字符串?有一個專門爲此目的的BlobRefProperty。 – 2011-03-28 23:57:29