I implemented a simple model that have an ImageField in Django Rest. It works great with Browsable API of Django Rest.
However, when I try to write test case to post a JSON, it raises error UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte
Below you can check test code. Basically, I open test image and pass it as JSON parameter I'm not sure why it cannot encode.
test_image_filename = os.path.join('/vagrant/', 'test_images', 'test_image1.jpg')
with open(test_image_filename) as image_file:
data = {
"location": "123, 123",
"location_name": "location1",
"date": datetime.datetime.now().__str__(),
"max_attendee": 10,
"description": "test",
"image": image_file,
"tags": []
}
response = self.client.post('/events/', data)
print response