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'

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

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

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay