Пример #1
0
    def get(self, action, asset_key, filename=''):

        asset_key = ndb.Key(urlsafe=asset_key)
        asset = asset_key.get()
        if not asset:
            return self.error(404)
        if not asset.blob:
            return self.error(404)

        blob_info = blobstore.get(asset.blob)
        if not blob_info:
            return self.error(404)

        value = BlobReader(blob_info.key(), buffer_size=blob_info.size).read()

        # The code works with or without the following line.
        #value = unicode(value.decode('utf8')).encode('utf8')[0:-2]
        value = base64.b64decode(value.split('base64,')[1])

        self.response.body = value

        self.response.headers['Content-Type'] = str(blob_info.content_type)
        if action == 'get':
            self.response.headers['Content-Disposition'] = str('attachment; filename=' + blob_info.filename)

        return self.response
Пример #2
0
 def test_blob_creation(self):
     import imghdr, StringIO
     data = 'some_image_data'
     when(StringIO).StringIO(data).thenReturn('data_file')
     when(imghdr).what('data_file').thenReturn('jpeg')
     
     image = Image.create(data=data)
     reader = BlobReader(image.blob_key)
     self.assertEqual(data, reader.read())
     image = image.key.get()
     self.assertEqual('image/jpeg', image.format)
Пример #3
0
def send_property_notification(property_listing, item_url):
    recipients_config = feed_config_connector.get_alert_recipients()
    recipients = ["%s <%s>" % (_['name'], _['email']) for _ in recipients_config]

    property_type_map = {
        'apartment': "Apartment",
        'condo': "Condo",
        'cottage/cabin': "Cottage/Cabin",
        'duplex': "Duplex",
        'flat': "Flat",
        'house': "House",
        'in-law': "In-Law",
        'townhouse': "Townhouse"
    }
    # TODO: use app_identity
    sender_address = "Rental Bot <*****@*****.**>"
    property_type = property_listing.property_types[0] \
        if property_listing.property_types else "Property"
    property_type_description = property_type_map.get(property_type, property_type)
    formatted_address = "%s, %s, %s %s" % (
        property_listing.address,
        property_listing.city,
        property_listing.state_code,
        property_listing.postal_code
    )
    geo = property_listing.geo
    subject = "%s in %s (%s)" % (
        property_type_description,
        property_listing.neighborhood,
        property_listing.address
    )
    message = mail.EmailMessage(
        sender=sender_address,
        subject=subject,
        to=recipients
    )

    message.body = item_url
    message.html = """<a href="{}">{}</a><br/>
<br/>
<a href="https://www.google.com/maps/place/{}/@{}">Google Maps</a><br/>


""".format(
    item_url,
    property_listing.title.encode('utf-8'),
    urllib.quote_plus(formatted_address),
    "%s,%s" % (geo.lat, geo.lon)
)
    blob_reader = BlobReader(property_listing.image.original_jpeg_blob_key)
    message.attachments=[("property.jpg", blob_reader.read())]
    message.send()
Пример #4
0
    def get(self):
        fileName = self.request.url[self.request.url.rfind('/')+1:]

        file = File.get_by_key_name(fileName)
        if file is None:
            self.error(404)
            return

        blob_key =  file.blobKey.key()
        blob_reader = BlobReader(blob_key)
        value = blob_reader.read() #TODO : test as it is not recommended for big files (https://developers.google.com/appengine/docs/python/blobstore/blobreaderclass)
        
        self.response.headers['Content-Type'] = 'application/octet-stream'
        self.response.out.write(value);
Пример #5
0
 def serve(self, filename):
     #TODO: Surely if this file is served from a hash-based URL then we
     #can return HTTP caching headers, right?
     info = BlobInfo.all().filter('filename = ', filename).get()
     if not info:
         return HttpResponseNotFound()
         #
     content = BlobReader(info.key()).read()
     return HttpResponse(content, mimetype=info.content_type)
Пример #6
0
 def __init__(self, blobinfo, charset):
     super(BlobstoreUploadedFile,
           self).__init__(BlobReader(blobinfo.key()), blobinfo.filename,
                          blobinfo.content_type, blobinfo.size, charset)
     self.blobstore_info = blobinfo
Пример #7
0
 def file(self):
     if not hasattr(self, '_file'):
         self._file = BlobReader(self.blobstore_info.key())
     return self._file
Пример #8
0
 def __init__(self, blobinfo, charset):
   logger.info('BlobstoreUploadedFile.__init__ %s', blobinfo.content_type)
   super(BlobstoreUploadedFile, self).__init__(
     BlobReader(blobinfo.key()), # read only file-like interface to blob
     blobinfo.filename, blobinfo.content_type, blobinfo.size, charset)
   self.blobstore_info = blobinfo