0

Refering to the example in the link: https://developers.google.com/appengine/docs/python/blobstore/overview

In the example above, a Model named _BlobInfo_ is created to store the blob.

Is there a way to store and retrieve blobs using user defined models: eg:

class DummyText(db.Model):
  ptxt = db.BlobProperty()

Note: I need to handle ".txt" file in the above model. Is there a way to do that?

topless
  • 8,069
  • 11
  • 57
  • 86
Jayaram
  • 761
  • 2
  • 9
  • 21

2 Answers2

3

For .txt files you could actually use the TextProperty() which can fit up to 1MB using db and unlimited size for ndb. In the background they are actually stored as blobs but it's much easier since blobs are immutable and cannot be changed.

I would suggest you also to upgrade to ndb.

topless
  • 8,069
  • 11
  • 57
  • 86
  • I tried to use the TextProperty(), but how can you convert the uploaded file to the text format. I use "upload_files = self.get_uploads('file')", but how can i retrive the .txt file contents once uploaded – Jayaram Apr 23 '13 at 11:46
  • 1
    There is an [answer](http://stackoverflow.com/questions/8369219/how-do-i-read-a-text-file-into-a-string-variable-in-python) for that. – topless Apr 23 '13 at 12:04
  • Can you give me a simple code snippet to do so,considering im uploading a text file using " ", What exactly should my python class in appengine do to retrive its contents. Thanks – Jayaram Apr 23 '13 at 12:26
  • 1
    I also found the below thread to be useful. [Stack Link](http://stackoverflow.com/questions/16186583/retrieving-txt-file-contents-in-google-appengine) and see [Blog.NotDot](http://blog.notdot.net/2009/9/Handling-file-uploads-in-App-Engine) for storing any file-types in blobstore. Thanks – Jayaram Apr 24 '13 at 14:16
2

You should use blobstore.BlobReferenceProperty in your model to store references to blobstore keys.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895