supload_1.py 514 B

12345678910111213141516
  1. def upload_file(file_name,in_sub_folder,bucket_name,supress_print=True):
  2. client = boto3.client('s3')
  3. fname = os.path.basename(file_name)
  4. str_dt = time.strftime("%m%d%Y")
  5. key = f'{in_sub_folder}/{str_dt}/{fname}'
  6. s3_url = f's3://{bucket_name}/{key}'
  7. try:
  8. client.upload_file(file_name, Bucket=bucket_name ,Key=key)
  9. if not supress_print:
  10. print(f'{fname}--->{key}')
  11. return True,s3_url
  12. except Exception as e:
  13. print(e)
  14. return False,s3_url