Hi i have a subfolders in my s3bucket,have to insert the files in that subfolders
i am not able to upload the file here is my code
def upload_to_aws(filedata,filename,timestamp,company_id,folder_id,size,status,created_by,folder_name):
s3 = boto3.client('s3', aws_access_key_id=settings.S3_BUCKET_BUCKET_AccessKeyId,
aws_secret_access_key=settings.S3_BUCKET_BUCKET_SecretAccessKey)
try:
curntfilename = filedata.name
isexist = False
for key in s3.list_objects(Bucket=settings.S3_BUCKET_BUCKET_NAME)['Contents']:
folder = key['Key']
if folder == (folder_name):
isexist = True
data = s3.upload_fileobj(filedata, settings.S3_BUCKET_BUCKET_NAME, '%s/%s' % (folder+'/'+created_by +'/' , filename))
uploadprofile(curntfilename,company_id,folder_id,size,status,created_by)
print("Upload Successful")
return True
except FileNotFoundError:
print("The file was not found")
return False
except NoCredentialsError:
print("Credentials not available")
return False
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…