1

Suppose I have a variable "profile_image" of image file type. I have created the variable like below:

profile_image = request.FILES.get('profile_image', False) 

Now I need to convert this image variable to bytes array. How can I do this without saving it to the local drive? I found that file open/read do not work here. I tried like below:

with open(profile_image.name, "rb") as imageFile:
       file_stream = imageFile.read()

Please help me. By the way, by converting into bytes array I want to save it to google cloud.

Thank you.

Mohammad Zakaria
  • 325
  • 4
  • 11

1 Answers1

5

After googling for a long time I found the solution Here.

Actually "profile_image" is an "InMemoryUploadedFile" object in python. We can read the file like below:

profile_image.file.read()
Mohammad Zakaria
  • 325
  • 4
  • 11