I have to upload images in s3 bucket in my django project. I'm using boto3 to the do the same as follows:
def handle_uploaded_file(file, filename):
s3 = boto3.resource('s3', aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY)
check = s3.Bucket(bucket).put_object(Key=filename, Body=file,ContentType='image/png',ACL='public-read')
return check
I'm calling this function in my API like this:
if request.FILES and request.FILES.get('tagimage', None) is not None:
tagimage = request.FILES['tagimage']
tagimage_name = tagimage.name
number = number_genarator()
tagimage_name = str(number) + tagimage_name
tag_upload = handle_uploaded_file(tagimage,tagimage_name)
res['tagimage']=tag_upload
record.tagimage = tagimage_name
But this process is taking too long as per me. To upload one image it's taking me three seconds barring the time needed for the other part of my API. Can someone suggest a faster way to upload images?