Exemplo n.º 1
0
    def import_image(self, filename, original_filename, bytes, date,
                     email_attachment_content_id):

        content_type = self.get_content_type(original_filename)
        self.original_size_key = filename
        filestore.write(self.original_size_key, bytes, content_type)

        MAX_SIZE = 500
        image = images.Image(bytes)

        if image.width <= MAX_SIZE and image.width <= MAX_SIZE:
            logging.info('%s is only %sx%s, no resizing will be done' %
                         (original_filename, image.width, image.height))
            resized_bytes = bytes
        else:
            if image.width > image.height:
                new_width = MAX_SIZE
                new_height = int(float(MAX_SIZE) / image.width * image.height)
            else:
                new_height = MAX_SIZE
                new_width = int(float(MAX_SIZE) / image.height * image.width)

            logging.info('Resizing %s from %sx%s to %sx%s' %
                         (original_filename, image.width, image.height,
                          new_width, new_height))
            resized_bytes = images.resize(bytes, MAX_SIZE, MAX_SIZE)

        self.serving_size_key = self.get_small_image_name(filename)
        filestore.write(self.serving_size_key, resized_bytes, content_type)
        self.original_filename = original_filename
        self.filename = filename

        self.email_attachment_content_id = email_attachment_content_id
        self.date = date
Exemplo n.º 2
0
	def import_image(self, filename, original_filename, bytes, date):

		content_type = self.get_content_type(original_filename)
		self.original_size_key = filename
		filestore.write(self.original_size_key, bytes, content_type)

		MAX_SIZE = 500
		image = images.Image(bytes)

		if image.width <= MAX_SIZE and image.width <= MAX_SIZE:
			logging.info('%s is only %sx%s, no resizing will be done' % (original_filename, image.width, image.height))
			resized_bytes = bytes
		else:
			if image.width > image.height:
				new_width = MAX_SIZE
				new_height = int(float(MAX_SIZE) / image.width * image.height)
			else:
				new_height = MAX_SIZE
				new_width = int(float(MAX_SIZE) / image.height * image.width)

			logging.info('Resizing %s from %sx%s to %sx%s' % (original_filename, image.width, image.height, new_width, new_height))
			resized_bytes = images.resize(bytes, MAX_SIZE, MAX_SIZE)


		self.serving_size_key = self.get_small_image_name(filename)
		filestore.write(self.serving_size_key, resized_bytes, content_type)
		self.original_filename = original_filename
		self.filename = filename
		self.date = date
Exemplo n.º 3
0
	def migrate_to_gcs(self):
		if self.original_size_key == self.filename:
			raise Exception('This image (%s) looks like it already is in GCS' % self.filename)

		content_type = self.get_content_type(self.filename)

		image_bytes = blobstore.BlobReader(self.original_size_key, buffer_size=1048576).read()
		small_image_bytes = blobstore.BlobReader(self.serving_size_key, buffer_size=1048576).read()

		self.original_size_key = self.filename
		self.serving_size_key = self.get_small_image_name(self.filename)

		filestore.write(self.original_size_key, image_bytes, content_type)
		filestore.write(self.serving_size_key, small_image_bytes, content_type)

		self.put()
Exemplo n.º 4
0
    def migrate_to_gcs(self):
        if self.original_size_key == self.filename:
            raise Exception('This image (%s) looks like it already is in GCS' %
                            self.filename)

        content_type = self.get_content_type(self.filename)

        image_bytes = blobstore.BlobReader(self.original_size_key,
                                           buffer_size=1048576).read()
        small_image_bytes = blobstore.BlobReader(self.serving_size_key,
                                                 buffer_size=1048576).read()

        self.original_size_key = self.filename
        self.serving_size_key = self.get_small_image_name(self.filename)

        filestore.write(self.original_size_key, image_bytes, content_type)
        filestore.write(self.serving_size_key, small_image_bytes, content_type)

        self.put()
Exemplo n.º 5
0
def note_page_POST():
    #Input via POST
    text_content = form.getvalue('textcontent')
    text_content = text_content.decode("utf-8")
    text_content = text_content.rstrip()
   
    filename = filestore.write(text_content) # write data to disk
   
    url = base_url + "/" + filename
   
    redirect = True #changes url in the address bar to new note url
    renderer(text_content, url, filename, redirect)
Exemplo n.º 6
0
	def create_zip_blob(self, buffer, filename):
		filestore.write(filename, buffer.getvalue(), content_type='application/zip')
Exemplo n.º 7
0
 def create_zip_blob(self, buffer, filename):
     filestore.write(filename,
                     buffer.getvalue(),
                     content_type='application/zip')