2π
β
@mariodev answered this in the comments yesterday:
Have you tried the rb flag instead of r?
This is because otherwise you uploading the file with an encoding. For text files, and other non-binary files, this shouldnβt be an issue, but for cases such as image files you need to open it as a binary file.
temp_file = open('hm.jpg',"rb")
When Django REST Framework checks that the image is valid using Pillow
, it will raise an exception if the encoding is wrong. This is why you are getting the error, as Django REST Framework got a file upload, but canβt verify that it is an image. The encoding was correct when using curl, because curl was uploading it as a binary file and was handling it all for you.
Source:stackexchange.com