2011-03-28 38 views
2

我做应用程序引擎的文档中指定的,但我不能让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> 
+0

你为什么存储Blob键为字符串?有一个专门为此目的的BlobRefProperty。 – 2011-03-28 23:57:29

回答

1

IIRC BlobstoreUploadHandler希望你返回重定向已处理的POST为您的处理程序后,确实应对特殊BLOBSTORE上传服务器和不与客户直接/浏览器就像在一个正常请求。

复制blobstore文档中的示例,并记住您可以仅使用以标题(如重定向)响应而不使用正文内容。

+0

谢谢您的回答,但即使我已经使用重定向它仍然无法正常工作。如果您可以提交我必须实施的部分代码才能使其工作,那将会很好。谢谢你的好意.. – gurkan 2011-03-28 14:07:33

+2

您可以更新您的问题,以反映你的代码,返回一个重定向,我会高兴地看一看。 *也请修复您的格式 - 代码需要打算与四个空格,以显示正确* – 2011-03-28 14:31:04

+0

“不工作”怎么样?你有没有看过日志,并且使用了Chrome开发者工具或者萤火虫来查看返回的内容? – 2011-03-28 23:56:58

相关问题