2012-03-31 156 views
2

我創建的斑點在GAE BLOBSTORE和successfuly創建這些文件,問題是,當我嘗試使用的BlobKey爲這些文件,我得到了內容長度= 0,因爲這樣:BLOB的Blob存儲在GAE

Status: 200 OK 
Cache-Control: no-cache 
X-AppEngine-BlobKey: crXwVb6vKoS8OykvgPmSew== 
Content-Type: application/zip 
Content-Disposition: attachment; filename="test.zip" 
Expires: Fri, 01 Jan 1990 00:00:00 GMT 
Content-Length: 0 

這樣(test.zip)是在BlobStore中創建的文件,我在管理控制檯中檢查了BlobStore併成功創建了此文件。 編輯: download.py代碼:

def mime_type(filename): 
    return guess_type(filename)[0] 
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): 
    def get(self): 

     blob_key = self.request.get('key') 
     blob_key = str(urllib.unquote(blob_key)) 
     blob_info = blobstore.BlobInfo.get(blob_key) 
     content_type1 =mime_type(blob_info.filename) 
     save_as1 = blob_info.filename 
     self.send_blob(blob_key,content_type=content_type1,save_as=save_as1) 



def main(): 

    application = webapp.WSGIApplication([ 
      (r'/download.*', ServeHandler), 
     ], debug=True) 
    run_wsgi_app(application) 



if __name__ == '__main__': 
    main() 

關鍵是在URL中存在如下:

http://localhost:8080/download.py?key=Es9f00P29wNTZoeL9ccS4g== 

,我得到它得到Blob存儲團塊。

在此先感謝。

+0

你能告訴處理程序? – 2012-03-31 09:11:23

+0

@Peter Knego:好的,我會編輯這個問題。 – 2012-03-31 09:51:29

+0

你從哪裏得到blobkey?它看起來像是Base64編碼的。 – 2012-03-31 12:32:10

回答

0

根據文檔字符串:

Args: 
    blob_key_or_info: BlobKey or BlobInfo record to serve. 
    content_type: Content-type to override when known. 
    save_as: If True, and BlobInfo record is provided, use BlobInfos 
    filename to save-as. If string is provided, use string as filename. 
    If None or False, do not send as attachment. 
    start: Start index of content-range to send. 
    end: End index of content-range to send. End index is inclusive. 
    use_range: Use provided content range from requests Range header. 
    Mutually exclusive to start and end. 

試着改變你的代碼

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): 
    def get(self): 
    blob_key = BlobKey(urllib.unquote(self.request.get('key'))) 
    self.send_blob(blob_key, save_as=True)