앱 엔진 문서에 명시된 모든 작업을 수행했지만 blobstore 작업을 수행 할 수 없습니다. 어쩌면 당신 중 일부는 내가 잘못하고있는 것을 발견 할 수 있습니다. 제출 버튼을 클릭했을 때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가 있습니다. –