[Answered ]-Django rest api test to upload file/image

2๐Ÿ‘

Ok, so I just had the exact same problem. This is how it worked for me:

    image_path = os.path.join('/vagrant/', 'test_image1.jpg')
    with open(image_path) as logo:
        encoded_logo = base64.b64encode(logo.read())
        data = {'name': 'Domus de magnum orexis, resuscitabo candidatus!', 
                'logo': encoded_logo,
                'about': 'The small planet revolutionary travels the phenomenon.'
            }
        response = self.client.post(url, data=json.dumps(data, ensure_ascii=False), content_type='application/json')

Hope this helps ๐Ÿ™‚

๐Ÿ‘คAdelaN

Leave a comment