Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:45:50+00:00 2026-06-11T14:45:50+00:00

+++ It is working – See solution at bottom +++ I am a relative

  • 0

+++ It is working – See solution at bottom +++

I am a relative newbie to Google App Engine and Python.

I have some large text content (content in a variable and not an external file) that I am manipulating in my program. GAE does not let me write to files so I would like to store them in blobstore. Can I do this in GAE and Python? and if so, how?

An example code snippet would be greatly appreciated.

Thanks.

+++ Updated Question +++

I tried following the example at the link you provided modified by the example at: http://blog.notdot.net/2010/03/Implementing-a-dropbox-service-with-the-Blobstore-API-Part-1 to enable the saving of the blobstore key in the datastore. When the time comes to retrieve the file (which is an html file), I want to retrieve the BlobKey using the TemplateName.

I ended up with something like this:

In models.py I have:

class GeneratedFiles(ndb.Model):
  TemplateName = ndb.StringProperty()
  BlobKey = blobstore.BlobReferenceProperty()
  Status = ndb.StringProperty(default="Pending Translation")

In a class, in a .py file I have:

class TokenFileGen(BaseHandler):
    def get(self):
        template = jinja_environment.get_template(FileName)     
        blobtext = template.render(tokenvals = tokendict)
        bloboutput = (blobtext.encode('utf-8'))
        # Create the file
        file_name = files.blobstore.create(mime_type='application/octet-stream')
        # Open the file and write to it
        with files.open(file_name, 'a') as fl:
            fl.write(bloboutput)
        # Finalize the file. Do this before attempting to read it.
        files.finalize(file_name)
        # Get the file's blob key
        blob_key = files.blobstore.get_blob_key(file_name)
        logging.info('QQQ: blob_key: %s' % blob_key)
        f = GeneratedFiles(
            TemplateName = templateName
            , BlobKey = blob_key                       
            , Status = 'Published'
            )
        f.put()
        ...

I get a TypeError(‘Cannot set non-property %s’ % name) TypeError: Cannot set non-property blob

My logging statement returned the following:
INFO 2012-09-21 05:20:24,177 token.py:551] QQQ: blob_key: vL117vQ4dlIPoUwXbREmbeqUnZU7nJ6ELMma8u1bFHGUfgEfOfS7HfAdFUvXc1EC

I thought I was following the example fairly closely. Any idea how I can get this to work?

Thanks for any assistance.

+++ update 2 +++

Ok, I am now able to save the Blobstore reference in the following model:

class GeneratedFiles(ndb.Model):
  TemplateName = ndb.StringProperty()
  BlobKey = ndb.BlobKeyProperty()

The code that saved this is:

file_name = files.blobstore.create(mime_type='application/octet-stream')
with files.open(file_name, 'a') as fl:
    fl.write(bloboutput)
files.finalize(file_name)
blob_key = files.blobstore.get_blob_key(file_name)
logging.info('QQQ: blob_key: %s' % blob_key)
f = GeneratedFiles(
    TemplateName = templateName
    , BlobKey = blob_key                       
    )
f.put()

I am now trying to retrieve and download the file:

class FileDownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self, genfile_id):
        iden = int(genfile_id)
        file_info = ndb.Key('GeneratedFiles', iden).get()
        if not file_info or not file_info.BlobKey:
            self.error(404)
            return
        else:
            blob_key = file_info.BlobKey
        logging.info('QQQ: FileDownloadHandler/blob_key: %s' % blob_key)
        self.send_blob(blob_key, save_as=True)

I am getting a error: ValueError: Expected BlobInfo value for blob_key_or_info. on the last line.

Just prior to the error msg, I get my log info:

INFO     2012-09-21 19:19:44,219 genfile.py:131] QQQ: FileDownloadHandler/blob_key: sGxZRNu94u1kZ9ezpAeQFhyOLSZFYNX8RSAbXU78MLjjUKOohV0wyWnZZEQf6ScC

I found some references that mention URLencoding in conjunction with this error. Could this be the problem? If so, what would URLencoding look like in my case and where should I place it (when I store the blob_key or after I retrieve id from ndb.datastore?

Thanks for any assistance.

+++ the solution +++

The key was changing the self.send_blob statement as follows (referencing blobstore and BlobInfo).

self.send_blob(blobstore.BlobInfo(file_info.blob), save_as=True)

I also changed the name of the attribute BlobKey to blob (was getting an error and error went away after I did this although I do not understand why that would make a difference).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:45:51+00:00Added an answer on June 11, 2026 at 2:45 pm

    Look at writing to the blobstore: https://developers.google.com/appengine/docs/python/blobstore/overview#Writing_Files_to_the_Blobstore

    You can give votes to comments as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on game where plates will be falling from top to bottom. Some plates
Working on a multi-tenant app where most of my models will have a tenant_id
Working with some basic java apps on CentOS 5 linux and I have my
Working with python interactively, it's sometimes necessary to display a result which is some
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working in an app where a page_title method was defined in application_helper.rb as such:
Working with a Lucene index, I have a standard document format that looks something
Working in Java: I have a JFrame class, and separate classes for my two
Working on my first Android app and facing a challenge. I am pulling calls
Working on game. I have a movable basket and a - for now -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.