コード例 #1
0
    async def multipart_upload(self,
                               Bucket=None,
                               Key=None,
                               Body=None,
                               ACL=None,
                               config=None,
                               callback=None,
                               **kwargs):

        if config is None:
            config = boto3.s3.transfer.TransferConfig()

        context = {'raw_body': Body}
        handler = EncryptionHandler(self.key_provider, self.encryption_mode)
        # with concurrent.futures.ThreadPoolExecutor() as pool:
        #     context = await self.loop.run_in_executor(
        #         pool, handler.build_request_context, context)

        if S3Action.MULTIPART_UPLOAD not in handler.actions_for_cipher():
            raise ValueError(
                'Current cipher can not be used for full multipart upload')

        context = handler.build_request_context(context)
        if ACL is not None:
            kwargs['ACL'] = ACL

        kwargs.update({'Metadata': context['envelope']})
        f = io.BytesIO(context['body'].full_data)

        await self.client.upload_fileobj(f,
                                         Bucket=Bucket,
                                         Key=Key,
                                         ExtraArgs=kwargs.copy(),
                                         Callback=callback,
                                         Config=config)