2011-03-28 81 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

相關問題