DEV Community

Bharathim31
Bharathim31

Posted on

2

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'

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs