Reputation: 2667
Is it possible to upload blob to blobstore using remote API (not the standard upload scheme)?
I want to write backup/restore script for my application and blobstore is the only thing that doesn't work.
Upvotes: 2
Views: 1020
Reputation: 1097
There's a better solution with the new files API: http://code.google.com/appengine/docs/python/blobstore/overview.html
This works well for me. Here is some sample code:
from __future__ import with_statement
from google.appengine.api import files
from google.appengine.ext import blobstore
def get_blob_key(self, data, _type):
# Create the file
file_name = files.blobstore.create(mime_type = _type)
# Open the file and write to it
with files.open(file_name, 'a') as f:
f.write(data)
# 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)
return blob_key
Upvotes: 0
Reputation: 2322
I once solved the problem of programmatically uploading to the blobstore and wrote a short tutorial/explanation for it on my blog. Hope it's useful: http://swizec.com/blog/programatically-uploading-to-blobstore-in-python/swizec/1423
Upvotes: 1
Reputation: 12981
Blobstore access over Remote API was added three days ago:
- Remote API now supports the Blobstore API. (Changelog)
remote_api works at the lowest level of the datastore, so once you've set up the stub, you don't have to worry about the fact that you're operating on a remote datastore: With a few caveats, it works exactly the same as if you were accessing the datastore directly. (App Engine Help)
Upvotes: 1