0

저는이 벽의 벽에 머리를 대고있었습니다. 웬일인지 Google App Engine의 여러 측면을 결합하여이 작업을 수행하는 데 어려움을 겪고 있습니다.BLOB를 데이터 스토어 엔티티에 연결

기본적으로 사용자가 아래 코드에서 작업 한 Blobstore에 사진을 업로드하도록 한 다음 BlobKey를 데이터베이스 엔터티에 저장 될 목록에 넣으려고합니다. 그래서 여기에 이미지를 업로드하는 코드가 있으며 여기에 BlobKey를 저장하여 저장할 수 있습니까? 여기

class MainHandler(BlogHandler): 
    def get(self): 
     upload_url = blobstore.create_upload_url('/upload') 
     self.response.out.write('<html><body>') 
     self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url) 
     self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit" name="submit" value="Submit"> </form></body></html>""") 
     #there is a lot more code in here where I get all the following info but it isn't relevant 
     location_db = Location(
        description=description, 
        submitter=submitter, 
        user_id=user_id, 
        title=title, 
        locationtype = locationtype) 
      #This is what I would like to do but I don't know where to get thr BlobKey 
      location_db.blobRefs.append(BlobKey) 
      location_db.put() 

     for b in blobstore.BlobInfo.all(): 
      self.response.out.write('<li><a href="/serve/%s' % str(b.key()) + '">' + str(b.filename) + '</a>') 

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler): 
    def post(self): 
     upload_files = self.get_uploads('file') 
     blob_info = upload_files[0] 
     self.redirect('/main') 

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): 
    def get(self, blob_key): 
     blob_key = str(urllib.unquote(blob_key)) 
     if not blobstore.get(blob_key): 
      self.error(404) 
     else: 
      self.send_blob(blobstore.BlobInfo.get(blob_key), save_as=True) 

답변

3

는 :

blob_info = upload_files[0] 
self.redirect('/serve/%s' % blob_info.key()) 

나는 당신이 누락

blob_info.key() 

있다고 생각합니다. 잡아서 목록에 넣으세요. 문서도 참고 :

이 핸들러에서 나머지 응용 프로그램의 데이터 모델과 함께 blob 키를 저장할 수 있습니다. blob 키 자체는 데이터 저장소의 BLOB 정보 엔티티에서 액세스 할 수 있습니다. https://developers.google.com/appengine/docs/python/blobstore/overview#Serving_a_Blob

+0

예, 거기에 약간의 상식을 사용해야했습니다. 감사! – clifgray