DEV Community

Bharathim31
Bharathim31

Posted on

ERROR: expected string or bytes-like object

HI Getting the below error while trying to upload the image into s3bucket
ERROR: expected string or bytes-like object

class ADDUploadProfile(APIView):
def post(self, request):
s3 = boto3.client('s3', aws_access_key_id=settings.S3_BUCKET_BUCKET_AccessKeyId, aws_secret_access_key=settings.S3_BUCKET_BUCKET_SecretAccessKey)
myfile = request.FILES['fileUpload']
object_name = None
if object_name is None:
object_name = myfile
# If S3 object_name was not specified, use file_name
# Upload the file
s3_client = boto3.client('s3')
s3_bucket = os.environ.get(settings.S3_BUCKET_BUCKET_NAME)
try:
# with open(myfile, 'rb') as f:
response=s3_client.upload_fileobj(myfile, s3_bucket, object_name)
except ClientError as e:
logging.error(e)
return False
return True

my setting.py

users = 'Employees'
users_path = os.path.join(BASE_DIR,'Employees')
S3_BUCKET_BUCKET_NAME ='voofisdevstorag'
S3_BUCKET_BUCKET_AccessKeyId = 'AKIAIP5VDKFHDVFTAATQ'
S3_BUCKET_BUCKET_SecretAccessKey = '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'
S3BucketLink = 'http://voffisdevstorage.s3.us-east-2.amazonaws.com/'
Profile ='local-test-profile'
Region ='US East (Ohio) us-east-2'

Top comments (0)