I am using django-avatars to process user profile avatars for my site. I am currently developing my own application for Android, which includes the ability to download avatars. I pass the image data through the get parameter encoded in base 64. In my Django view, I have
data = base64.b64decode(request.POST['data'])
out = open("etc/test.jpeg", "wb")
out.write(data)
out.close()
to decode the image. This works fine (test.jpeg is the file I want it to be), but I am having trouble linking this to django avatars.
Looking through the source of django-avatars, the following is used to create a new avatar:
avatar = Avatar(
user = request.user,
primary = True,
)
image_file = request.FILES['avatar']
avatar.avatar.save(image_file.name, image_file)
avatar.save()
My question is how can I convert the data of my file to the required request.FILES format (or what is the easiest way to rewrite the save method to accept my format)