本文整理汇总了Python中boto.s3.connection.Key.set_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python Key.set_metadata方法的具体用法?Python Key.set_metadata怎么用?Python Key.set_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.s3.connection.Key
的用法示例。
在下文中一共展示了Key.set_metadata方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_metadata [as 别名]
def upload(self):
for destination, data, content_type, compressed in self.get_files():
key = Key(self.bucket)
key.content_type = content_type
if compressed:
key.set_metadata('content-encoding', 'gzip')
for header, value in self.headers:
key.set_metadata(header, value)
key.key = destination
key.set_contents_from_string(data)
示例2: add_bucket
# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_metadata [as 别名]
def add_bucket(self,bucket_name,access,zonename,create_date):
try:
bucket_count=len(self.conn.get_all_buckets())
# print 'bucket_count is %s ' %bucket_count
if bucket_count < self.bucket_limit:
self.conn.create_bucket(bucket_name)
b=self.conn.get_bucket(bucket_name)
try:
# k=b.new_key('create_info')
# k.set_contents_from_string("{'bucket_name':'%s','zonename':'%s','access':'%s','create_date':'%s'}" %(bucket_name,zonename,access,create_date))
k1=Key(b)
k1.key='create_info'
#k1.set_metadata('Bucket_Name',bucket_name),注意,在设置元数据的时候key名不能带有下划线,该示例在创建的时候会报错403
k1.set_metadata('BucketName',bucket_name)
k1.set_metadata('ZoneName',zonename)
k1.set_metadata('Access',access)
k1.set_metadata('CreateDate',create_date)
k1.set_contents_from_string('')
except Exception as e:
print r'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\',e
return True
else:
return False
except Exception as e:
return False
示例3: _upload_file_to_bucket
# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_metadata [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))
示例4: __key
# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_metadata [as 别名]
def __key(cls,k=None):
from boto.s3.connection import Key
from time import gmtime
from calendar import timegm
from random import choice
from string import ascii_lowercase as letters
if k is None:
key = Key(cls.__bucket())
k = ''
for i in range(12):
k += choice(letters)
key.key = k
key.set_metadata('time',timegm(gmtime()))
else:
key = cls.__bucket().get_key(k)
return key
示例5: save_tree
# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_metadata [as 别名]
def save_tree(self, target, new_tree):
self.connect()
now_dt = datetime.utcnow()
now_dt_str = now_dt.strftime('%Y%m%dT%H%M')
sio = StringIO()
tree.save_tree(new_tree, sio)
# Save to S3
print("Saving tree to S3")
s3_pf_prefix = self.cp.get('options', 's3-pf-prefix')
k = Key(self.s3_bucket)
k.key = '{}/trees/{}.{}'.format(
s3_pf_prefix,
target,
now_dt_str
)
k.set_metadata('pf:target', target)
k.set_metadata('pf:saved_dt', now_dt_str)
k.set_contents_from_string(sio.getvalue())
示例6: upload_file
# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_metadata [as 别名]
def upload_file(conn, full_path):
b = Bucket(conn, BUCKET)
k = Key(b)
k.key = full_path
expires = datetime.utcnow() + timedelta(days=(25 * 365))
expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
k.set_metadata("Content-Type", mimetypes.guess_type(full_path)[0])
k.set_metadata("Expires", expires)
k.set_metadata("Cache-Control", "max-age={0}, public".format(25 * 365 * 36400))
k.set_contents_from_filename(full_path)
k.set_acl('public-read')
print "{} -> http://s3.amazonaws.com/yaluandmike/{}".format(full_path, full_path)
示例7: process_file
# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import set_metadata [as 别名]
def process_file(aws_conn, filepath):
mtime = get_mtime(filepath)
name_200 = add_size_name(filepath, '200')
name_800 = add_size_name(filepath, '800')
mtime_200 = get_mtime(name_200)
mtime_800 = get_mtime(name_800)
im = None
if mtime_200 is None or mtime_200 < mtime:
try:
im = Image.open(filepath)
except:
return None
generate_200(im, name_200)
if mtime_800 is None or mtime_800 < mtime:
if im is None:
try:
im = Image.open(filepath)
except:
return None
generate_800(im, name_800)
names = {
'original': filepath,
'thumbnail': name_200,
'display': name_800,
}
b = Bucket(aws_conn, BUCKET)
image_result = {}
for image_type, name in names.items():
aws_tag_path = add_size_name(name, 's3t') + '.meta'
aws_key_path = name[len(GALLERY_DIR):].strip('/')
image_result[image_type] = {
'url': 'http://s3.amazonaws.com/{}/{}'.format(
BUCKET,
aws_key_path)
}
if not is_newer(name, aws_tag_path):
try:
resolution = load_data(aws_tag_path)
resolution['width']
except:
resolution = get_resolution(name)
save_data(aws_tag_path, resolution)
image_result[image_type].update(resolution)
continue
resolution = get_resolution(name)
image_result.update(resolution)
save_data(aws_tag_path, resolution)
s3key = b.get_key(aws_key_path)
mtime = get_mtime(name)
if s3key and s3key.last_modified:
print datetime.datetime(*parsedate(s3key.last_modified)[:6])
print mtime
if datetime.datetime(*parsedate(s3key.last_modified)[:6]) > mtime:
with open(aws_tag_path, 'a'):
os.utime(aws_tag_path, None)
continue
print 'Sending {} to S3'.format(name)
k = Key(b)
k.key = aws_key_path
expires = datetime.datetime.utcnow() + datetime.timedelta(days=25 * 365)
expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
k.set_metadata("Content-Type", mimetypes.guess_type(name)[0])
k.set_metadata("Expires", expires)
k.set_metadata("Cache-Control", "max-age={0}, public".format(86400 * 365 * 25))
k.set_contents_from_filename(name)
k.set_acl('public-read')
with open(aws_tag_path, 'a'):
os.utime(aws_tag_path, None)
photo_age = get_photo_age(filepath)
image_result['caption'] = get_caption(filepath)
return photo_age, image_result