示例#1
0
 def _fs_opened(self, fs, error):
     if error:
         self.result(xmlrpclib.Fault(500, str(error)))
     else:
         # This is the tail end of the URL, like 2012/06/foo.png
         now = datetime.datetime.utcnow()
         self.mlink = media_link(now.year, now.month, self.name)
         fs.new_file(
             filename=self.mlink,
             content_type=self.media_type,
             callback=self._new_file)
示例#2
0
    def store_image(self, name, content, content_type):
        """Put an image in GridFS, and return the URL."""
        fs = motor.MotorGridFS(self.settings['db'])

        # This is the tail end of the URL, like 2012/06/foo.png.
        now = datetime.datetime.utcnow()
        fullname = media_link(now.year, now.month, name)
        gridin = yield fs.new_file(filename=fullname,
                                   content_type=content_type)

        yield gridin.write(content)
        yield gridin.close()
        raise gen.Return(self.application.reverse_url('media', fullname))
示例#3
0
    def store_image(self, name, content, content_type):
        """Put an image in GridFS, and return the URL."""
        fs = motor.MotorGridFS(self.settings['db'])

        # This is the tail end of the URL, like 2012/06/foo.png.
        now = datetime.datetime.utcnow()
        fullname = media_link(now.year, now.month, name)
        gridin = yield fs.new_file(
            filename=fullname,
            content_type=content_type)

        yield gridin.write(content)
        yield gridin.close()
        raise gen.Return(self.application.reverse_url('media', fullname))
示例#4
0
    def metaWeblog_newMediaObject(self, blogid, user, password, struct):
        name = struct['name']
        content = struct['bits'].data # xmlrpclib created a 'Binary' object
        media_type = struct['type']
        now = datetime.datetime.utcnow()

        # This is the tail end of the URL, like 2012/06/foo.png
        mlink = media_link(now.year, now.month, name)

        def inserted(_id, error):
            if error:
                self.result(xmlrpclib.Fault(500, str(error)))
            else:
                full_link = absolute(os.path.join(opts.base_url, 'media', mlink))
                self.result({'file': name, 'url': full_link, 'type': media_type})

        self.settings['db'].media.insert({
            'content': bson.Binary(content), 'type': media_type, '_id': mlink,
            'length': len(content), 'mod': now,
        }, callback=inserted)
示例#5
0
    def metaWeblog_newMediaObject(self, blogid, user, password, struct):
        name = struct['name']
        content = struct['bits'].data # xmlrpclib created a 'Binary' object
        media_type = struct['type']
        now = datetime.datetime.utcnow()

        # This is the tail end of the URL, like 2012/06/foo.png
        mlink = media_link(now.year, now.month, name)

        def inserted(_id, error):
            if error:
                raise error

            full_link = absolute(os.path.join(opts.base_url, 'media', mlink))
            self.result({'file': name, 'url': full_link, 'type': media_type})

        self.settings['db'].media.insert({
            'content': bson.Binary(content), 'type': media_type, '_id': mlink,
            'mod': now,
        }, callback=inserted)
示例#6
0
    def store_image(self, name, content, content_type, maxwidth, callback):
        try:
            # In a higher-volume site this work should be offloaded to a queue
            resized_content, width, height = image.resized(content, maxwidth)
            fs = yield motor.Op(motor.MotorGridFS(self.settings['db']).open)

            # This is the tail end of the URL, like 2012/06/foo.png
            now = datetime.datetime.utcnow()
            mlink = media_link(now.year, now.month, name)
            gridin = yield motor.Op(fs.new_file,
                filename=mlink,
                content_type=content_type,
                # GridFS stores any metadata we want
                width=width,
                height=height)

            yield motor.Op(gridin.write, resized_content)
            yield motor.Op(gridin.close)
            callback((mlink, width, height), None)
        except Exception, e:
            callback(None, e)
示例#7
0
    def store_image(self, name, content, content_type, maxwidth):
        """Put an image in GridFS.

        Returns (url, width, height).
        """
        # In a higher-volume site this work should be offloaded to a queue.
        resized_content, width, height = image.resized(content, maxwidth)
        fs = yield motor.MotorGridFS(self.settings['db']).open()

        # This is the tail end of the URL, like 2012/06/foo.png.
        now = datetime.datetime.utcnow()
        mlink = media_link(now.year, now.month, name)
        gridin = yield fs.new_file(
            filename=mlink,
            content_type=content_type,
            # GridFS stores any metadata we want
            width=width,
            height=height)

        yield gridin.write(resized_content)
        yield gridin.close()
        raise gen.Return((mlink, width, height))