Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

How to upload the files in subfolders in s3bucket using python boto3

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...