codekingpro/portable-devtools
114k
1# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"). You4# may not use this file except in compliance with the License. A copy of5# the License is located at6#7# https://aws.amazon.com/apache2.0/8#9# or in the "license" file accompanying this file. This file is10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF11# ANY KIND, either express or implied. See the License for the specific12# language governing permissions and limitations under the License.13import copy as python_copy14 15from botocore.exceptions import ClientError16 17from boto3 import utils18from boto3.s3.transfer import (19 ProgressCallbackInvoker,20 S3Transfer,21 TransferConfig,22 create_transfer_manager,23)24 25 26def inject_s3_transfer_methods(class_attributes, **kwargs):27 utils.inject_attribute(class_attributes, 'upload_file', upload_file)28 utils.inject_attribute(class_attributes, 'download_file', download_file)29 utils.inject_attribute(class_attributes, 'copy', copy)30 utils.inject_attribute(class_attributes, 'upload_fileobj', upload_fileobj)31 utils.inject_attribute(32 class_attributes, 'download_fileobj', download_fileobj33 )34 35 36def inject_bucket_methods(class_attributes, **kwargs):37 utils.inject_attribute(class_attributes, 'load', bucket_load)38 utils.inject_attribute(class_attributes, 'upload_file', bucket_upload_file)39 utils.inject_attribute(40 class_attributes, 'download_file', bucket_download_file41 )42 utils.inject_attribute(class_attributes, 'copy', bucket_copy)43 utils.inject_attribute(44 class_attributes, 'upload_fileobj', bucket_upload_fileobj45 )46 utils.inject_attribute(47 class_attributes, 'download_fileobj', bucket_download_fileobj48 )49 50 51def inject_object_methods(class_attributes, **kwargs):52 utils.inject_attribute(class_attributes, 'upload_file', object_upload_file)53 utils.inject_attribute(54 class_attributes, 'download_file', object_download_file55 )56 utils.inject_attribute(class_attributes, 'copy', object_copy)57 utils.inject_attribute(58 class_attributes, 'upload_fileobj', object_upload_fileobj59 )60 utils.inject_attribute(61 class_attributes, 'download_fileobj', object_download_fileobj62 )63 64 65def inject_object_summary_methods(class_attributes, **kwargs):66 utils.inject_attribute(class_attributes, 'load', object_summary_load)67 68 69def bucket_load(self, *args, **kwargs):70 """71 Calls s3.Client.list_buckets() to update the attributes of the Bucket72 resource.73 """74 # The docstring above is phrased this way to match what the autogenerated75 # docs produce.76 77 # We can't actually get the bucket's attributes from a HeadBucket,78 # so we need to use a ListBuckets and search for our bucket.79 # However, we may fail if we lack permissions to ListBuckets80 # or the bucket is in another account. In which case, creation_date81 # will be None.82 self.meta.data = {}83 try:84 response = self.meta.client.list_buckets()85 for bucket_data in response['Buckets']:86 if bucket_data['Name'] == self.name:87 self.meta.data = bucket_data88 break89 except ClientError as e:90 if not e.response.get('Error', {}).get('Code') == 'AccessDenied':91 raise92 93 94def object_summary_load(self, *args, **kwargs):95 """96 Calls s3.Client.head_object to update the attributes of the ObjectSummary97 resource.98 """99 response = self.meta.client.head_object(100 Bucket=self.bucket_name, Key=self.key101 )102 if 'ContentLength' in response:103 response['Size'] = response.pop('ContentLength')104 self.meta.data = response105 106 107def upload_file(108 self, Filename, Bucket, Key, ExtraArgs=None, Callback=None, Config=None109):110 """Upload a file to an S3 object.111 112 Usage::113 114 import boto3115 s3 = boto3.client('s3')116 s3.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')117 118 Similar behavior as S3Transfer's upload_file() method, except that119 argument names are capitalized. Detailed examples can be found at120 :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.121 122 :type Filename: str123 :param Filename: The path to the file to upload.124 125 :type Bucket: str126 :param Bucket: The name of the bucket to upload to.127 128 :type Key: str129 :param Key: The name of the key to upload to.130 131 :type ExtraArgs: dict132 :param ExtraArgs: Extra arguments that may be passed to the133 client operation. For allowed upload arguments see134 boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.135 136 :type Callback: function137 :param Callback: A method which takes a number of bytes transferred to138 be periodically called during the upload.139 140 :type Config: boto3.s3.transfer.TransferConfig141 :param Config: The transfer configuration to be used when performing the142 transfer.143 """144 with S3Transfer(self, Config) as transfer:145 return transfer.upload_file(146 filename=Filename,147 bucket=Bucket,148 key=Key,149 extra_args=ExtraArgs,150 callback=Callback,151 )152 153 154def download_file(155 self, Bucket, Key, Filename, ExtraArgs=None, Callback=None, Config=None156):157 """Download an S3 object to a file.158 159 Usage::160 161 import boto3162 s3 = boto3.resource('s3')163 s3.meta.client.download_file('mybucket', 'hello.txt', '/tmp/hello.txt')164 165 Similar behavior as S3Transfer's download_file() method,166 except that parameters are capitalized. Detailed examples can be found at167 :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.168 169 :type Bucket: str170 :param Bucket: The name of the bucket to download from.171 172 :type Key: str173 :param Key: The name of the key to download from.174 175 :type Filename: str176 :param Filename: The path to the file to download to.177 178 :type ExtraArgs: dict179 :param ExtraArgs: Extra arguments that may be passed to the180 client operation. For allowed download arguments see181 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.182 183 :type Callback: function184 :param Callback: A method which takes a number of bytes transferred to185 be periodically called during the download.186 187 :type Config: boto3.s3.transfer.TransferConfig188 :param Config: The transfer configuration to be used when performing the189 transfer.190 """191 with S3Transfer(self, Config) as transfer:192 return transfer.download_file(193 bucket=Bucket,194 key=Key,195 filename=Filename,196 extra_args=ExtraArgs,197 callback=Callback,198 )199 200 201def bucket_upload_file(202 self, Filename, Key, ExtraArgs=None, Callback=None, Config=None203):204 """Upload a file to an S3 object.205 206 Usage::207 208 import boto3209 s3 = boto3.resource('s3')210 s3.Bucket('mybucket').upload_file('/tmp/hello.txt', 'hello.txt')211 212 Similar behavior as S3Transfer's upload_file() method,213 except that parameters are capitalized. Detailed examples can be found at214 :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.215 216 :type Filename: str217 :param Filename: The path to the file to upload.218 219 :type Key: str220 :param Key: The name of the key to upload to.221 222 :type ExtraArgs: dict223 :param ExtraArgs: Extra arguments that may be passed to the224 client operation. For allowed upload arguments see225 boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.226 227 :type Callback: function228 :param Callback: A method which takes a number of bytes transferred to229 be periodically called during the upload.230 231 :type Config: boto3.s3.transfer.TransferConfig232 :param Config: The transfer configuration to be used when performing the233 transfer.234 """235 return self.meta.client.upload_file(236 Filename=Filename,237 Bucket=self.name,238 Key=Key,239 ExtraArgs=ExtraArgs,240 Callback=Callback,241 Config=Config,242 )243 244 245def bucket_download_file(246 self, Key, Filename, ExtraArgs=None, Callback=None, Config=None247):248 """Download an S3 object to a file.249 250 Usage::251 252 import boto3253 s3 = boto3.resource('s3')254 s3.Bucket('mybucket').download_file('hello.txt', '/tmp/hello.txt')255 256 Similar behavior as S3Transfer's download_file() method,257 except that parameters are capitalized. Detailed examples can be found at258 :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.259 260 :type Key: str261 :param Key: The name of the key to download from.262 263 :type Filename: str264 :param Filename: The path to the file to download to.265 266 :type ExtraArgs: dict267 :param ExtraArgs: Extra arguments that may be passed to the268 client operation. For allowed download arguments see269 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.270 271 :type Callback: function272 :param Callback: A method which takes a number of bytes transferred to273 be periodically called during the download.274 275 :type Config: boto3.s3.transfer.TransferConfig276 :param Config: The transfer configuration to be used when performing the277 transfer.278 """279 return self.meta.client.download_file(280 Bucket=self.name,281 Key=Key,282 Filename=Filename,283 ExtraArgs=ExtraArgs,284 Callback=Callback,285 Config=Config,286 )287 288 289def object_upload_file(290 self, Filename, ExtraArgs=None, Callback=None, Config=None291):292 """Upload a file to an S3 object.293 294 Usage::295 296 import boto3297 s3 = boto3.resource('s3')298 s3.Object('mybucket', 'hello.txt').upload_file('/tmp/hello.txt')299 300 Similar behavior as S3Transfer's upload_file() method,301 except that parameters are capitalized. Detailed examples can be found at302 :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.303 304 :type Filename: str305 :param Filename: The path to the file to upload.306 307 :type ExtraArgs: dict308 :param ExtraArgs: Extra arguments that may be passed to the309 client operation. For allowed upload arguments see310 boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.311 312 :type Callback: function313 :param Callback: A method which takes a number of bytes transferred to314 be periodically called during the upload.315 316 :type Config: boto3.s3.transfer.TransferConfig317 :param Config: The transfer configuration to be used when performing the318 transfer.319 """320 return self.meta.client.upload_file(321 Filename=Filename,322 Bucket=self.bucket_name,323 Key=self.key,324 ExtraArgs=ExtraArgs,325 Callback=Callback,326 Config=Config,327 )328 329 330def object_download_file(331 self, Filename, ExtraArgs=None, Callback=None, Config=None332):333 """Download an S3 object to a file.334 335 Usage::336 337 import boto3338 s3 = boto3.resource('s3')339 s3.Object('mybucket', 'hello.txt').download_file('/tmp/hello.txt')340 341 Similar behavior as S3Transfer's download_file() method,342 except that parameters are capitalized. Detailed examples can be found at343 :ref:`S3Transfer's Usage <ref_s3transfer_usage>`.344 345 :type Filename: str346 :param Filename: The path to the file to download to.347 348 :type ExtraArgs: dict349 :param ExtraArgs: Extra arguments that may be passed to the350 client operation. For allowed download arguments see351 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.352 353 :type Callback: function354 :param Callback: A method which takes a number of bytes transferred to355 be periodically called during the download.356 357 :type Config: boto3.s3.transfer.TransferConfig358 :param Config: The transfer configuration to be used when performing the359 transfer.360 """361 return self.meta.client.download_file(362 Bucket=self.bucket_name,363 Key=self.key,364 Filename=Filename,365 ExtraArgs=ExtraArgs,366 Callback=Callback,367 Config=Config,368 )369 370 371def copy(372 self,373 CopySource,374 Bucket,375 Key,376 ExtraArgs=None,377 Callback=None,378 SourceClient=None,379 Config=None,380):381 """Copy an object from one S3 location to another.382 383 This is a managed transfer which will perform a multipart copy in384 multiple threads if necessary.385 386 Usage::387 388 import boto3389 s3 = boto3.resource('s3')390 copy_source = {391 'Bucket': 'mybucket',392 'Key': 'mykey'393 }394 s3.meta.client.copy(copy_source, 'otherbucket', 'otherkey')395 396 :type CopySource: dict397 :param CopySource: The name of the source bucket, key name of the398 source object, and optional version ID of the source object. The399 dictionary format is:400 ``{'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}``. Note401 that the ``VersionId`` key is optional and may be omitted.402 403 :type Bucket: str404 :param Bucket: The name of the bucket to copy to405 406 :type Key: str407 :param Key: The name of the key to copy to408 409 :type ExtraArgs: dict410 :param ExtraArgs: Extra arguments that may be passed to the411 client operation. For allowed download arguments see412 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.413 414 :type Callback: function415 :param Callback: A method which takes a number of bytes transferred to416 be periodically called during the copy.417 418 :type SourceClient: botocore or boto3 Client419 :param SourceClient: The client to be used for operation that420 may happen at the source object. For example, this client is421 used for the head_object that determines the size of the copy.422 If no client is provided, the current client is used as the client423 for the source object.424 425 :type Config: boto3.s3.transfer.TransferConfig426 :param Config: The transfer configuration to be used when performing the427 copy.428 """429 subscribers = None430 if Callback is not None:431 subscribers = [ProgressCallbackInvoker(Callback)]432 433 config = Config434 if config is None:435 config = TransferConfig()436 437 # copy is not supported in the CRT438 new_config = python_copy.copy(config)439 new_config.preferred_transfer_client = "classic"440 441 with create_transfer_manager(self, new_config) as manager:442 future = manager.copy(443 copy_source=CopySource,444 bucket=Bucket,445 key=Key,446 extra_args=ExtraArgs,447 subscribers=subscribers,448 source_client=SourceClient,449 )450 return future.result()451 452 453def bucket_copy(454 self,455 CopySource,456 Key,457 ExtraArgs=None,458 Callback=None,459 SourceClient=None,460 Config=None,461):462 """Copy an object from one S3 location to an object in this bucket.463 464 This is a managed transfer which will perform a multipart copy in465 multiple threads if necessary.466 467 Usage::468 469 import boto3470 s3 = boto3.resource('s3')471 copy_source = {472 'Bucket': 'mybucket',473 'Key': 'mykey'474 }475 bucket = s3.Bucket('otherbucket')476 bucket.copy(copy_source, 'otherkey')477 478 :type CopySource: dict479 :param CopySource: The name of the source bucket, key name of the480 source object, and optional version ID of the source object. The481 dictionary format is:482 ``{'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}``. Note483 that the ``VersionId`` key is optional and may be omitted.484 485 :type Key: str486 :param Key: The name of the key to copy to487 488 :type ExtraArgs: dict489 :param ExtraArgs: Extra arguments that may be passed to the490 client operation. For allowed download arguments see491 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.492 493 :type Callback: function494 :param Callback: A method which takes a number of bytes transferred to495 be periodically called during the copy.496 497 :type SourceClient: botocore or boto3 Client498 :param SourceClient: The client to be used for operation that499 may happen at the source object. For example, this client is500 used for the head_object that determines the size of the copy.501 If no client is provided, the current client is used as the client502 for the source object.503 504 :type Config: boto3.s3.transfer.TransferConfig505 :param Config: The transfer configuration to be used when performing the506 copy.507 """508 return self.meta.client.copy(509 CopySource=CopySource,510 Bucket=self.name,511 Key=Key,512 ExtraArgs=ExtraArgs,513 Callback=Callback,514 SourceClient=SourceClient,515 Config=Config,516 )517 518 519def object_copy(520 self,521 CopySource,522 ExtraArgs=None,523 Callback=None,524 SourceClient=None,525 Config=None,526):527 """Copy an object from one S3 location to this object.528 529 This is a managed transfer which will perform a multipart copy in530 multiple threads if necessary.531 532 Usage::533 534 import boto3535 s3 = boto3.resource('s3')536 copy_source = {537 'Bucket': 'mybucket',538 'Key': 'mykey'539 }540 bucket = s3.Bucket('otherbucket')541 obj = bucket.Object('otherkey')542 obj.copy(copy_source)543 544 :type CopySource: dict545 :param CopySource: The name of the source bucket, key name of the546 source object, and optional version ID of the source object. The547 dictionary format is:548 ``{'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}``. Note549 that the ``VersionId`` key is optional and may be omitted.550 551 :type ExtraArgs: dict552 :param ExtraArgs: Extra arguments that may be passed to the553 client operation. For allowed download arguments see554 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.555 556 :type Callback: function557 :param Callback: A method which takes a number of bytes transferred to558 be periodically called during the copy.559 560 :type SourceClient: botocore or boto3 Client561 :param SourceClient: The client to be used for operation that562 may happen at the source object. For example, this client is563 used for the head_object that determines the size of the copy.564 If no client is provided, the current client is used as the client565 for the source object.566 567 :type Config: boto3.s3.transfer.TransferConfig568 :param Config: The transfer configuration to be used when performing the569 copy.570 """571 return self.meta.client.copy(572 CopySource=CopySource,573 Bucket=self.bucket_name,574 Key=self.key,575 ExtraArgs=ExtraArgs,576 Callback=Callback,577 SourceClient=SourceClient,578 Config=Config,579 )580 581 582def upload_fileobj(583 self, Fileobj, Bucket, Key, ExtraArgs=None, Callback=None, Config=None584):585 """Upload a file-like object to S3.586 587 The file-like object must be in binary mode.588 589 This is a managed transfer which will perform a multipart upload in590 multiple threads if necessary.591 592 Usage::593 594 import boto3595 s3 = boto3.client('s3')596 597 with open('filename', 'rb') as data:598 s3.upload_fileobj(data, 'mybucket', 'mykey')599 600 :type Fileobj: a file-like object601 :param Fileobj: A file-like object to upload. At a minimum, it must602 implement the `read` method, and must return bytes.603 604 :type Bucket: str605 :param Bucket: The name of the bucket to upload to.606 607 :type Key: str608 :param Key: The name of the key to upload to.609 610 :type ExtraArgs: dict611 :param ExtraArgs: Extra arguments that may be passed to the612 client operation. For allowed upload arguments see613 boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.614 615 :type Callback: function616 :param Callback: A method which takes a number of bytes transferred to617 be periodically called during the upload.618 619 :type Config: boto3.s3.transfer.TransferConfig620 :param Config: The transfer configuration to be used when performing the621 upload.622 """623 if not hasattr(Fileobj, 'read'):624 raise ValueError('Fileobj must implement read')625 626 subscribers = None627 if Callback is not None:628 subscribers = [ProgressCallbackInvoker(Callback)]629 630 config = Config631 if config is None:632 config = TransferConfig()633 634 with create_transfer_manager(self, config) as manager:635 future = manager.upload(636 fileobj=Fileobj,637 bucket=Bucket,638 key=Key,639 extra_args=ExtraArgs,640 subscribers=subscribers,641 )642 return future.result()643 644 645def bucket_upload_fileobj(646 self, Fileobj, Key, ExtraArgs=None, Callback=None, Config=None647):648 """Upload a file-like object to this bucket.649 650 The file-like object must be in binary mode.651 652 This is a managed transfer which will perform a multipart upload in653 multiple threads if necessary.654 655 Usage::656 657 import boto3658 s3 = boto3.resource('s3')659 bucket = s3.Bucket('mybucket')660 661 with open('filename', 'rb') as data:662 bucket.upload_fileobj(data, 'mykey')663 664 :type Fileobj: a file-like object665 :param Fileobj: A file-like object to upload. At a minimum, it must666 implement the `read` method, and must return bytes.667 668 :type Key: str669 :param Key: The name of the key to upload to.670 671 :type ExtraArgs: dict672 :param ExtraArgs: Extra arguments that may be passed to the673 client operation. For allowed upload arguments see674 boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.675 676 :type Callback: function677 :param Callback: A method which takes a number of bytes transferred to678 be periodically called during the upload.679 680 :type Config: boto3.s3.transfer.TransferConfig681 :param Config: The transfer configuration to be used when performing the682 upload.683 """684 return self.meta.client.upload_fileobj(685 Fileobj=Fileobj,686 Bucket=self.name,687 Key=Key,688 ExtraArgs=ExtraArgs,689 Callback=Callback,690 Config=Config,691 )692 693 694def object_upload_fileobj(695 self, Fileobj, ExtraArgs=None, Callback=None, Config=None696):697 """Upload a file-like object to this object.698 699 The file-like object must be in binary mode.700 701 This is a managed transfer which will perform a multipart upload in702 multiple threads if necessary.703 704 Usage::705 706 import boto3707 s3 = boto3.resource('s3')708 bucket = s3.Bucket('mybucket')709 obj = bucket.Object('mykey')710 711 with open('filename', 'rb') as data:712 obj.upload_fileobj(data)713 714 :type Fileobj: a file-like object715 :param Fileobj: A file-like object to upload. At a minimum, it must716 implement the `read` method, and must return bytes.717 718 :type ExtraArgs: dict719 :param ExtraArgs: Extra arguments that may be passed to the720 client operation. For allowed upload arguments see721 boto3.s3.transfer.S3Transfer.ALLOWED_UPLOAD_ARGS.722 723 :type Callback: function724 :param Callback: A method which takes a number of bytes transferred to725 be periodically called during the upload.726 727 :type Config: boto3.s3.transfer.TransferConfig728 :param Config: The transfer configuration to be used when performing the729 upload.730 """731 return self.meta.client.upload_fileobj(732 Fileobj=Fileobj,733 Bucket=self.bucket_name,734 Key=self.key,735 ExtraArgs=ExtraArgs,736 Callback=Callback,737 Config=Config,738 )739 740 741def download_fileobj(742 self, Bucket, Key, Fileobj, ExtraArgs=None, Callback=None, Config=None743):744 """Download an object from S3 to a file-like object.745 746 The file-like object must be in binary mode.747 748 This is a managed transfer which will perform a multipart download in749 multiple threads if necessary.750 751 Usage::752 753 import boto3754 s3 = boto3.client('s3')755 756 with open('filename', 'wb') as data:757 s3.download_fileobj('mybucket', 'mykey', data)758 759 :type Bucket: str760 :param Bucket: The name of the bucket to download from.761 762 :type Key: str763 :param Key: The name of the key to download from.764 765 :type Fileobj: a file-like object766 :param Fileobj: A file-like object to download into. At a minimum, it must767 implement the `write` method and must accept bytes.768 769 :type ExtraArgs: dict770 :param ExtraArgs: Extra arguments that may be passed to the771 client operation. For allowed download arguments see772 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.773 774 :type Callback: function775 :param Callback: A method which takes a number of bytes transferred to776 be periodically called during the download.777 778 :type Config: boto3.s3.transfer.TransferConfig779 :param Config: The transfer configuration to be used when performing the780 download.781 """782 if not hasattr(Fileobj, 'write'):783 raise ValueError('Fileobj must implement write')784 785 subscribers = None786 if Callback is not None:787 subscribers = [ProgressCallbackInvoker(Callback)]788 789 config = Config790 if config is None:791 config = TransferConfig()792 793 with create_transfer_manager(self, config) as manager:794 future = manager.download(795 bucket=Bucket,796 key=Key,797 fileobj=Fileobj,798 extra_args=ExtraArgs,799 subscribers=subscribers,800 )801 return future.result()802 803 804def bucket_download_fileobj(805 self, Key, Fileobj, ExtraArgs=None, Callback=None, Config=None806):807 """Download an object from this bucket to a file-like-object.808 809 The file-like object must be in binary mode.810 811 This is a managed transfer which will perform a multipart download in812 multiple threads if necessary.813 814 Usage::815 816 import boto3817 s3 = boto3.resource('s3')818 bucket = s3.Bucket('mybucket')819 820 with open('filename', 'wb') as data:821 bucket.download_fileobj('mykey', data)822 823 :type Fileobj: a file-like object824 :param Fileobj: A file-like object to download into. At a minimum, it must825 implement the `write` method and must accept bytes.826 827 :type Key: str828 :param Key: The name of the key to download from.829 830 :type ExtraArgs: dict831 :param ExtraArgs: Extra arguments that may be passed to the832 client operation. For allowed download arguments see833 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.834 835 :type Callback: function836 :param Callback: A method which takes a number of bytes transferred to837 be periodically called during the download.838 839 :type Config: boto3.s3.transfer.TransferConfig840 :param Config: The transfer configuration to be used when performing the841 download.842 """843 return self.meta.client.download_fileobj(844 Bucket=self.name,845 Key=Key,846 Fileobj=Fileobj,847 ExtraArgs=ExtraArgs,848 Callback=Callback,849 Config=Config,850 )851 852 853def object_download_fileobj(854 self, Fileobj, ExtraArgs=None, Callback=None, Config=None855):856 """Download this object from S3 to a file-like object.857 858 The file-like object must be in binary mode.859 860 This is a managed transfer which will perform a multipart download in861 multiple threads if necessary.862 863 Usage::864 865 import boto3866 s3 = boto3.resource('s3')867 bucket = s3.Bucket('mybucket')868 obj = bucket.Object('mykey')869 870 with open('filename', 'wb') as data:871 obj.download_fileobj(data)872 873 :type Fileobj: a file-like object874 :param Fileobj: A file-like object to download into. At a minimum, it must875 implement the `write` method and must accept bytes.876 877 :type ExtraArgs: dict878 :param ExtraArgs: Extra arguments that may be passed to the879 client operation. For allowed download arguments see880 boto3.s3.transfer.S3Transfer.ALLOWED_DOWNLOAD_ARGS.881 882 :type Callback: function883 :param Callback: A method which takes a number of bytes transferred to884 be periodically called during the download.885 886 :type Config: boto3.s3.transfer.TransferConfig887 :param Config: The transfer configuration to be used when performing the888 download.889 """890 return self.meta.client.download_fileobj(891 Bucket=self.bucket_name,892 Key=self.key,893 Fileobj=Fileobj,894 ExtraArgs=ExtraArgs,895 Callback=Callback,896 Config=Config,897 )898 