Пример #1
0
    def _BlobKey(cls, blob_key):
        """Normalize to instance of BlobKey."""

        if not isinstance(blob_key, blobstore.BlobKey):
            return blobstore.BlobKey(unicode(blob_key))

        return blob_key
Пример #2
0
    def _BlobKey(cls, blob_key):
        """Normalize to instance of BlobKey.
 
    Args:
      blob_key: A blob key of a blob to store.
    Returns:
      A normalized blob key of class BlobKey.
    """
        if not isinstance(blob_key, blobstore.BlobKey):
            return blobstore.BlobKey(unicode(blob_key))
        return blob_key
Пример #3
0
    def save_image(cls, photo, user_key=None):
        img_title = photo.filename
        img_content = photo.file.read()
        img_type = photo.type

        cloud_storage_path = '/gs/fooddonation/%s/%s' % (user_key.id(),
                                                         img_title)
        blobstore_key = blobstore.create_gs_key(cloud_storage_path)
        print blobstore_key
        cloud_storage_file = cloudstorage_api.open(
            filename=cloud_storage_path[3:], mode='w', content_type=img_type)
        cloud_storage_file.write(img_content)
        cloud_storage_file.close()

        blobstore_key = blobstore.BlobKey(blobstore_key)
        serving_url = images.get_serving_url(blobstore_key)
        print serving_url
        return {'serving_url': serving_url, 'blobstore_key': blobstore_key}
Пример #4
0
    def save_image(cls, photo, user_key):
        img_title = photo.filename
        img_content = photo.file.read()
        img_type = photo.type
        #todd-search-images is a google cloud bucket
        cloud_storage_path = '/gs/todd-search-images/%s/%s' % (user_key.id(),
                                                               img_title)
        blobstore_key = blobstore.create_gs_key(cloud_storage_path)

        cloud_storage_file = cloudstorage_api.open(
            filename=cloud_storage_path[3:], mode='w', content_type=img_type)
        cloud_storage_file.write(img_content)
        cloud_storage_file.close()

        blobstore_key = blobstore.BlobKey(blobstore_key)
        serving_url = images.get_serving_url(blobstore_key)

        return {'serving_url': serving_url, 'blobstore_key': blobstore_key}
Пример #5
0
    def create_blob(self):
        """Create a blob in the datastore and on disk.

    Returns:
      BlobKey of new blob.
    """
        contents = 'a blob'
        blob_key = blobstore.BlobKey('blob-key-1')
        self.blob_storage.StoreBlob(blob_key, cStringIO.StringIO(contents))
        entity = datastore.Entity(blobstore.BLOB_INFO_KIND,
                                  name=str(blob_key),
                                  namespace='')
        entity['content_type'] = 'image/png'
        entity['creation'] = datetime.datetime(1999, 10, 10, 8, 42, 0)
        entity['filename'] = 'largeblob.png'
        entity['size'] = len(contents)
        datastore.Put(entity)

        return blob_key
Пример #6
0
    def post(self):
        """POST handler."""
        path = self.request.get('path')
        # Must use str_POST here to preserve the original encoding of the string.
        content = self.request.str_POST.get('content')
        blob = self.request.get('blob', None)

        try:
            file_kwargs, method_kwargs = _GetExtraParams(self.request.POST)
        except ValueError:
            self.error(400)
            return

        if blob is not None:
            # Convert any string keys to BlobKey instances.
            if isinstance(blob, basestring):
                blob = blobstore.BlobKey(blob)

        meta = self.request.get('meta', None)
        if meta:
            meta = json.loads(meta)
        mime_type = self.request.get('mime_type', None)

        try:
            files.File(path, **file_kwargs).write(content,
                                                  blob=blob,
                                                  mime_type=mime_type,
                                                  meta=meta,
                                                  **method_kwargs)
            self.response.set_status(201)
            # Headers must be byte-strings, not unicode strings.
            # Since this is a URI, follow RFC 3986 and encode it using UTF-8.
            location_header = ('/_titan/file/?path=%s' % path).encode('utf-8')
            self.response.headers['Location'] = location_header
        except files.BadFileError:
            self.error(404)
        except (TypeError, ValueError):
            self.error(400)
            _MaybeLogException('Bad request:')
 def DeleteBlob(self, blob_key):
   """Deletes blob content."""
   try:
     del self._blobs[blobstore.BlobKey(unicode(blob_key))]
   except KeyError:
     pass
 def OpenBlob(self, blob_key):
   """Gets the blob contents as a stream."""
   return StringIO.StringIO(
       self._blobs[blobstore.BlobKey(unicode(blob_key))])
 def CreateBlob(self, blob_key, blob):
   """Stores a blob in a map."""
   self._blobs[blobstore.BlobKey(unicode(blob_key))] = blob
Пример #10
0
 def DeleteBlob(self, blob_key):
   """Delete blob content."""
   try:
     del self._blobs[blobstore.BlobKey(six.text_type(blob_key))]
   except KeyError:
     pass
Пример #11
0
 def OpenBlob(self, blob_key):
   """Get blob contents as stream."""
   return io.StringIO(
       self._blobs[blobstore.BlobKey(six.text_type(blob_key))])
Пример #12
0
 def CreateBlob(self, blob_key, blob):
   """Store blob in map."""
   self._blobs[blobstore.BlobKey(six.text_type(blob_key))] = blob
Пример #13
0
 def _BlobKey(cls, blob_key):
     """Normalize to instance of BlobKey."""
     if not isinstance(blob_key, blobstore.BlobKey):
         return blobstore.BlobKey(six.text_type(blob_key))
     return blob_key