本文整理汇总了Python中boto3.s3.transfer.S3Transfer方法的典型用法代码示例。如果您正苦于以下问题:Python transfer.S3Transfer方法的具体用法?Python transfer.S3Transfer怎么用?Python transfer.S3Transfer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto3.s3.transfer
的用法示例。
在下文中一共展示了transfer.S3Transfer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def upload_file(self, Filename, Bucket, Key, ExtraArgs=None,
Callback=None, Config=None):
"""Upload a file to an S3 object.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.meta.client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')
Similar behavior as S3Transfer's upload_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
"""
with S3Transfer(self, Config) as transfer:
return transfer.upload_file(
filename=Filename, bucket=Bucket, key=Key,
extra_args=ExtraArgs, callback=Callback)
示例2: download_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def download_file(self, Bucket, Key, Filename, ExtraArgs=None,
Callback=None, Config=None):
"""Download an S3 object to a file.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.meta.client.download_file('mybucket', 'hello.txt', '/tmp/hello.txt')
Similar behavior as S3Transfer's download_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
"""
with S3Transfer(self, Config) as transfer:
return transfer.download_file(
bucket=Bucket, key=Key, filename=Filename,
extra_args=ExtraArgs, callback=Callback)
示例3: bucket_upload_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def bucket_upload_file(self, Filename, Key,
ExtraArgs=None, Callback=None, Config=None):
"""Upload a file to an S3 object.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.Bucket('mybucket').upload_file('/tmp/hello.txt', 'hello.txt')
Similar behavior as S3Transfer's upload_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
"""
return self.meta.client.upload_file(
Filename=Filename, Bucket=self.name, Key=Key,
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
示例4: bucket_download_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def bucket_download_file(self, Key, Filename,
ExtraArgs=None, Callback=None, Config=None):
"""Download an S3 object to a file.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.Bucket('mybucket').download_file('hello.txt', '/tmp/hello.txt')
Similar behavior as S3Transfer's download_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
"""
return self.meta.client.download_file(
Bucket=self.name, Key=Key, Filename=Filename,
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
示例5: object_upload_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def object_upload_file(self, Filename,
ExtraArgs=None, Callback=None, Config=None):
"""Upload a file to an S3 object.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.Object('mybucket', 'hello.txt').upload_file('/tmp/hello.txt')
Similar behavior as S3Transfer's upload_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
"""
return self.meta.client.upload_file(
Filename=Filename, Bucket=self.bucket_name, Key=self.key,
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
示例6: zip_and_upload
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def zip_and_upload(app_dir, bucket, key, session=None):
"""Zip built static site and upload to S3."""
if session:
s3_client = session.client('s3')
else:
s3_client = boto3.client('s3')
transfer = S3Transfer(s3_client)
filedes, temp_file = tempfile.mkstemp()
os.close(filedes)
LOGGER.info("staticsite: archiving app at %s to s3://%s/%s",
app_dir, bucket, key)
with zipfile.ZipFile(temp_file, 'w', zipfile.ZIP_DEFLATED) as filehandle:
with change_dir(app_dir):
for dirname, _subdirs, files in os.walk('./'):
if dirname != './':
filehandle.write(dirname)
for filename in files:
filehandle.write(os.path.join(dirname, filename))
transfer.upload_file(temp_file, bucket, key)
os.remove(temp_file)
示例7: __init__
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def __init__(self, *args, **kwargs):
MarketRecorder.__init__(self, *args, **kwargs)
self._bucket = self.context["bucket"]
self._data_type = self.context.get("data_type", "marketdata")
self.s3 = boto3.client("s3")
transfer_config = TransferConfig(use_threads=False)
self.transfer = S3Transfer(self.s3, config=transfer_config)
示例8: __init__
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def __init__(self, ctx, config):
super().__init__(ctx, config)
# can't use a local session as we dont want an unassumed session cached.
self.transfer = S3Transfer(
self.ctx.session_factory(assume=False).client('s3'))
示例9: _upload_func
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def _upload_func(self, s3_uri, func, archive):
from boto3.s3.transfer import S3Transfer, TransferConfig
_, bucket, key_prefix = parse_s3(s3_uri)
key = "%s/%s" % (key_prefix, func.name)
transfer = S3Transfer(
self.session_factory().client('s3'),
config=TransferConfig(
multipart_threshold=1024 * 1024 * 4))
transfer.upload_file(
archive.path,
bucket=bucket,
key=key,
extra_args={
'ServerSideEncryption': 'AES256'})
return bucket, key
示例10: upload_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def upload_file(self, Filename, Bucket, Key, ExtraArgs=None,
Callback=None, Config=None):
"""Upload a file to an S3 object.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.meta.client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')
Similar behavior as S3Transfer's upload_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
:type Filename: str
:param Filename: The path to the file to upload.
:type Bucket: str
:param Bucket: The name of the bucket to upload to.
:type Key: str
:param Key: The name of the key to upload to.
:type ExtraArgs: dict
:param ExtraArgs: Extra arguments that may be passed to the
client operation.
:type Callback: function
:param Callback: A method which takes a number of bytes transferred to
be periodically called during the upload.
:type Config: boto3.s3.transfer.TransferConfig
:param Config: The transfer configuration to be used when performing the
transfer.
"""
with S3Transfer(self, Config) as transfer:
return transfer.upload_file(
filename=Filename, bucket=Bucket, key=Key,
extra_args=ExtraArgs, callback=Callback)
示例11: download_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def download_file(self, Bucket, Key, Filename, ExtraArgs=None,
Callback=None, Config=None):
"""Download an S3 object to a file.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.meta.client.download_file('mybucket', 'hello.txt', '/tmp/hello.txt')
Similar behavior as S3Transfer's download_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
:type Filename: str
:param Filename: The path to the file to download to.
:type Bucket: str
:param Bucket: The name of the bucket to download from.
:type Key: str
:param Key: The name of the key to download from.
:type ExtraArgs: dict
:param ExtraArgs: Extra arguments that may be passed to the
client operation.
:type Callback: function
:param Callback: A method which takes a number of bytes transferred to
be periodically called during the download.
:type Config: boto3.s3.transfer.TransferConfig
:param Config: The transfer configuration to be used when performing the
transfer.
"""
with S3Transfer(self, Config) as transfer:
return transfer.download_file(
bucket=Bucket, key=Key, filename=Filename,
extra_args=ExtraArgs, callback=Callback)
示例12: bucket_upload_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def bucket_upload_file(self, Filename, Key,
ExtraArgs=None, Callback=None, Config=None):
"""Upload a file to an S3 object.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.Bucket('mybucket').upload_file('/tmp/hello.txt', 'hello.txt')
Similar behavior as S3Transfer's upload_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
:type Filename: str
:param Filename: The path to the file to upload.
:type Key: str
:param Key: The name of the key to upload to.
:type ExtraArgs: dict
:param ExtraArgs: Extra arguments that may be passed to the
client operation.
:type Callback: function
:param Callback: A method which takes a number of bytes transferred to
be periodically called during the upload.
:type Config: boto3.s3.transfer.TransferConfig
:param Config: The transfer configuration to be used when performing the
transfer.
"""
return self.meta.client.upload_file(
Filename=Filename, Bucket=self.name, Key=Key,
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
示例13: bucket_download_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def bucket_download_file(self, Key, Filename,
ExtraArgs=None, Callback=None, Config=None):
"""Download an S3 object to a file.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.Bucket('mybucket').download_file('hello.txt', '/tmp/hello.txt')
Similar behavior as S3Transfer's download_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
:type Filename: str
:param Filename: The path to the file to download to.
:type Key: str
:param Key: The name of the key to download from.
:type ExtraArgs: dict
:param ExtraArgs: Extra arguments that may be passed to the
client operation.
:type Callback: function
:param Callback: A method which takes a number of bytes transferred to
be periodically called during the download.
:type Config: boto3.s3.transfer.TransferConfig
:param Config: The transfer configuration to be used when performing the
transfer.
"""
return self.meta.client.download_file(
Bucket=self.name, Key=Key, Filename=Filename,
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
示例14: object_upload_file
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def object_upload_file(self, Filename,
ExtraArgs=None, Callback=None, Config=None):
"""Upload a file to an S3 object.
Usage::
import boto3
s3 = boto3.resource('s3')
s3.Object('mybucket', 'hello.txt').upload_file('/tmp/hello.txt')
Similar behavior as S3Transfer's upload_file() method,
except that parameters are capitalized. Detailed examples can be found at
:ref:`S3Transfer's Usage <ref_s3transfer_usage>`.
:type Filename: str
:param Filename: The path to the file to upload.
:type ExtraArgs: dict
:param ExtraArgs: Extra arguments that may be passed to the
client operation.
:type Callback: function
:param Callback: A method which takes a number of bytes transferred to
be periodically called during the upload.
:type Config: boto3.s3.transfer.TransferConfig
:param Config: The transfer configuration to be used when performing the
transfer.
"""
return self.meta.client.upload_file(
Filename=Filename, Bucket=self.bucket_name, Key=self.key,
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
示例15: download
# 需要导入模块: from boto3.s3 import transfer [as 别名]
# 或者: from boto3.s3.transfer import S3Transfer [as 别名]
def download(bucket, key, file_path, session=None):
"""Download a file from S3 to the given path."""
s3_client = _get_client(session)
transfer = S3Transfer(s3_client)
transfer.download_file(bucket, key, file_path)
return file_path