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


Python Key.set_contents_from_file方法代码示例

本文整理汇总了Python中boto.s3.connection.Key.set_contents_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Key.set_contents_from_file方法的具体用法?Python Key.set_contents_from_file怎么用?Python Key.set_contents_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.s3.connection.Key的用法示例。


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

示例1: screenshot

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_contents_from_file [as 别名]
def screenshot(request,val):
	if val == 1 :
		conn = S3Connection('##', '##')
		bucket = conn.get_bucket('lheston-bucket')
		k = Key(bucket)
		k.key = '//lab3' + request + '_toS3.png'
		driver = webdriver.PhantomJS() # or add to your PATH                                                                
		driver.set_window_size(1024, 768) # optional                                                                        
		driver.get(request)
		driver.save_screenshot('tempfile.png')
		driver.quit
		file1 = open('tempfile.png', 'rb')
		os.remove('tempfile.png')
		k.set_contents_from_file(file1)
		driver.quit
		return str(request + '_toS3.png')
	elif val == 2:
		text = '/lab3' + request
		conn = S3Connection('##', '##')
		S3_BUCKET_NAME = 'lheston-bucket'
		bucket = Bucket(conn, S3_BUCKET_NAME)
		bucket = bucket.delete_key(text)
		#bucket.delete_key('/lab3/' + request.split(':')[1])
		#k = Key(b)
		#k.name = k.get_key(text)
		#b.delete_key(k)
		#k.name = k.get_key(text)
		#b.delete_key(k)
		#b.delete_key('//lab3' + request.split(':')[1] + '_toS3.png')
	else:
		return str('incorrect input')
开发者ID:lheston,项目名称:lab1,代码行数:33,代码来源:views.py

示例2: upload_to_s3

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_contents_from_file [as 别名]
def upload_to_s3(fp, name):
    conn = _get_s3_connection()
    bucket = conn.create_bucket('muxlist')
    k = Key(bucket)
    k.key = name
    k.set_contents_from_file(fp)
    return 'http://muxlist.s3.amazonaws.com/%s' % name
开发者ID:tpetr,项目名称:muxlist,代码行数:9,代码来源:utils.py

示例3: upload_content

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_contents_from_file [as 别名]
def upload_content(bucket=None, key_name=None, 
                    data_type=kUploadContentType.String, data=None) :
    bucket = get_bucket(bucket)
    bucketKey = Key(bucket)
    bucketKey.key = key_name
    try :
        if data_type == kUploadContentType.String :
            bucketKey.set_contents_from_string(data)
        elif data_type == kUploadContentType.File :
            bucketKey.set_contents_from_file(data)
        elif data_type == kUploadContentType.FileName(data) :
            bucketKey.set_contents_from_filename(data)
        elif data_type == kUploadContentType.Stream :
            bucketKey.set_contents_from_stream(data)
        return True
    except Exception, e :
        return False
开发者ID:lunayo,项目名称:Brazaar,代码行数:19,代码来源:storage.py

示例4: _upload_file_to_bucket

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_contents_from_file [as 别名]
    def _upload_file_to_bucket(self, file_path, destination):

        file_name = os.path.basename(file_path)
        destination_path = os.path.join(destination, file_name)
        log_info("Uploading '%s' to s3 bucket '%s' to '%s'" %
                (file_path, self.bucket_name, destination))

        file_obj = open(file_path)
        k = Key(self.bucket)
        k.key = destination_path
        # set meta data (has to be before setting content in
        # order for it to work)
        k.set_metadata("Content-Type", "application/x-compressed")

        k.set_contents_from_file(file_obj)

        log_info("Completed upload '%s' to s3 bucket '%s'!" %
                 (file_path, self.bucket_name))
开发者ID:hongchoi,项目名称:mongoctl,代码行数:20,代码来源:binary_repo.py

示例5: post

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_contents_from_file [as 别名]
def post():
    data = request.form 
    files = request.files

    # adds a modicum of security... 
    code = data.get('code')
    if code != os.environ.get('SEKKRIT_CODE'):
        err = Response(response="{'error':'unauthorized'}", status=401, mimetype="application/json")
        return err
    
    f = files.get('image')
    b = conn.get_bucket(S3_BUCKET)
    k = Key(b)
    
    path = data.get('filename')
    k.key = path
    k.set_contents_from_file(f)
    k.set_acl("public-read")

    #update the list of URLs stored in redis
    get_latest()

    #return the file name because reasons
    return json.dumps({"file" : path})
开发者ID:krushton,项目名称:mirror-server,代码行数:26,代码来源:app.py

示例6: store_image

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_contents_from_file [as 别名]
 def store_image(self, callback, image_id, request, body=None, filename=None, **kwargs):
     bucket = self._get_bucket()
     image = Key(bucket, image_id)
     image.set_contents_from_file(body)
     callback(image.generate_url(HOUR))
开发者ID:globocom,项目名称:impim-api,代码行数:7,代码来源:s3.py


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