Skip to content

Instantly share code, notes, and snippets.

@mcotton
Created December 19, 2017 15:02
Show Gist options
  • Save mcotton/7c7e47755e0f2384c14333f5f0223f04 to your computer and use it in GitHub Desktop.
Save mcotton/7c7e47755e0f2384c14333f5f0223f04 to your computer and use it in GitHub Desktop.
Attaching items uploaded to GCS to media objects
execfile('remote.py')
set_current_namespace('mcotton')
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
import cloudstorage as gcs
blob_key = blobstore.create_gs_key('/gs/' + s.GCS_BUCKET + '/152_592.zip')
billy = blobstore.BlobKey(blob_key)
zippy = gcs.stat('/' + s.GCS_BUCKET + '/152_592.zip')
proj = Project.query(Project.title=='I want BBQ').get()
media = Media(project=proj.key,
company=proj.company,
blob_key=billy,
file_size=zippy.st_size,
file_name=zippy.filename.replace('/'+s.GCS_BUCKET + '/', ''), original_file_name=zippy.filename.replace('/'+s.GCS_BUCKET + '/', ''),
mime_type=zippy.content_type.encode('ascii'), gcs_filename=zippy.filename)
media.put()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment