12345678910111213141516171819202122232425 |
- def upload_files(self, list_of_files):
- """upload_files on success of validation, this method uploads the give list of files to s3 bucket"""
- if self.__validation_result:
- self.count = 0 # local variable which tells count of files uploaded in S3 Buckets
- print(
- "Sample of file to be uploaded to S3 Buckets are \t {} ".format(
- list_of_files[:20]))
- for each_file in tqdm(list_of_files):
- try:
- self.__s3_resource = boto3.resource(service_name='s3',
- aws_access_key_id=self.__access_key,
- aws_secret_access_key=self.__secret_access_key,
- region_name=self.__region)
- self.__s3_resource.Bucket(self.__bucket).upload_file(
- Filename=each_file, Key=self.s3_file_name)
- # .upload_file from boto3 package uploads file to s3
- self.count += 1
- except Exception as e:
- print("Failed to upload file\n {}".format(each_file, e))
- else:
- print("please update the credentials to proceed further")
- print("Total file successfully uploaded:\t {}".format(self.count))
- return True
|