当前位置: 首页>>代码示例>>Python>>正文


Python s3cp.send_file函数代码示例

本文整理汇总了Python中r2.lib.s3cp.send_file函数的典型用法代码示例。如果您正苦于以下问题:Python send_file函数的具体用法?Python send_file怎么用?Python send_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了send_file函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_sr_image

def save_sr_image(sr, data, num = None):
    """
    uploades image data to s3 as a PNG and returns its new url.  Urls
    will be of the form:
      http:/${g.s3_thumb_bucket}/${sr._fullname}[_${num}].png?v=${md5hash}
    [Note: g.s3_thumb_bucket begins with a "/" so the above url is valid.]
    """
    import tempfile
    from r2.lib import s3cp
    from md5 import md5

    hash = md5(data).hexdigest()

    try:
        f = tempfile.NamedTemporaryFile(suffix = '.png')
        f.write(data)
        f.flush()

        resource = g.s3_thumb_bucket + sr._fullname
        if num is not None:
            resource += '_' + str(num)
        resource += '.png'
        
        s3cp.send_file(f.name, resource, 'image/png', 'public-read', 
                       None, False)
    finally:
        f.close()

    return 'http:/%s%s?v=%s' % (g.s3_thumb_bucket, 
                                resource.split('/')[-1], hash)
开发者ID:vin,项目名称:reddit,代码行数:30,代码来源:cssfilter.py

示例2: save_sr_image

def save_sr_image(sr, data, resource = None):
    """
    uploades image data to s3 as a PNG and returns its new url.  Urls
    will be of the form:
      http://${g.s3_thumb_bucket}/${sr._fullname}[_${num}].png?v=${md5hash}
    [Note: g.s3_thumb_bucket begins with a "/" so the above url is valid.]
    """
    hash = md5(data).hexdigest()

    f = tempfile.NamedTemporaryFile(suffix = '.png',delete=False)
    try:
        f.write(data)
        f.close()

        optimize_png(f.name, g.png_optimizer)
        contents = open(f.name).read()

        if resource is not None:
            resource = "_%s" % resource
        else:
            resource = ""
        fname = resource = sr._fullname + resource + ".png"

        s3cp.send_file(g.s3_thumb_bucket, fname, contents, 'image/png')

    finally:
        os.unlink(f.name)

    return 'http://%s/%s?v=%s' % (g.s3_thumb_bucket, 
                                  resource.split('/')[-1], hash)
开发者ID:DeanHyde,项目名称:reddit,代码行数:30,代码来源:cssfilter.py

示例3: s3_upload_media

def s3_upload_media(data, file_name, file_type, mime_type, never_expire):
    bucket = filename_to_s3_bucket(file_name)
    s3cp.send_file(bucket, file_name+file_type, data, mime_type,
                       never_expire=never_expire,
                       replace = False,
                       reduced_redundancy=True)
    if g.s3_media_direct:
        return "http://%s/%s/%s%s" % (s3_direct_url, bucket, file_name, file_type)
    else:
        return "http://%s/%s%s" % (bucket, file_name, file_type)
开发者ID:Krenair,项目名称:reddit,代码行数:10,代码来源:media.py

示例4: upload_thumb

def upload_thumb(link, image):
    """Given a link and an image, uploads the image to s3 into an image
    based on the link's fullname"""
    f = tempfile.NamedTemporaryFile(suffix = '.png')
    image.save(f)

    resource = s3_thumbnail_bucket + link._fullname + '.png'
    log.debug('uploading to s3: %s' % link._fullname)
    s3cp.send_file(f.name, resource, 'image/png', 'public-read', None, False)
    log.debug('thumbnail %s: %s' % (link._fullname, thumbnail_url(link)))
开发者ID:DFectuoso,项目名称:culter,代码行数:10,代码来源:media.py

示例5: upload_thumb

def upload_thumb(link, image):
    """Given a link and an image, uploads the image to s3 into an image
    based on the link's fullname"""
    f = tempfile.NamedTemporaryFile(suffix = '.png', delete=False)
    try:
        image.save(f)
        f.close()
        g.log.debug("optimizing %s in %s" % (link._fullname,f.name))
        optimize_png(f.name, g.png_optimizer)
        contents = open(f.name).read()

        s3fname = link._fullname + '.png'

        log.debug('uploading to s3: %s' % link._fullname)
        s3cp.send_file(g.s3_thumb_bucket, s3fname, contents, 'image/png', never_expire=True)
        log.debug('thumbnail %s: %s' % (link._fullname, thumbnail_url(link)))
    finally:
        os.unlink(f.name)
开发者ID:denrobapps,项目名称:Reddit-VM,代码行数:18,代码来源:media.py

示例6: change_css

    def change_css(self, content, parsed, prev=None, reason=None, author=None, force=False):
        from r2.models import ModAction

        author = author if author else c.user.name
        if content is None:
            content = ""
        try:
            wiki = WikiPage.get(self, "config/stylesheet")
        except tdb_cassandra.NotFound:
            wiki = WikiPage.create(self, "config/stylesheet")
        wr = wiki.revise(content, previous=prev, author=author, reason=reason, force=force)

        minified = cssmin(parsed)
        if minified:
            if g.static_stylesheet_bucket:
                digest = hashlib.sha1(minified).digest()
                self.stylesheet_hash = base64.urlsafe_b64encode(digest).rstrip("=")

                s3cp.send_file(
                    g.static_stylesheet_bucket,
                    self.static_stylesheet_name,
                    minified,
                    content_type="text/css",
                    never_expire=True,
                    replace=False,
                )

                self.stylesheet_contents = ""
                self.stylesheet_modified = None
            else:
                self.stylesheet_hash = hashlib.md5(minified).hexdigest()
                self.stylesheet_contents = minified
                self.stylesheet_modified = datetime.datetime.now(g.tz)
        else:
            self.stylesheet_contents = ""
            self.stylesheet_hash = ""
            self.stylesheet_modified = datetime.datetime.now(g.tz)
        self.stylesheet_contents_user = ""  # reads from wiki; ensure pg clean
        self._commit()

        ModAction.create(self, c.user, action="wikirevise", details="Updated subreddit stylesheet")
        return wr
开发者ID:nborwankar,项目名称:reddit,代码行数:42,代码来源:subreddit.py


注:本文中的r2.lib.s3cp.send_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。