I'm trying to send an image android(client) to django(server) by converting it into base64 string. I've received the string @ the server side, decoded and renamed it.However, when I try to save the image it fails.
Here's the path where the image is supposed to be stored on the server. models.py
class App(models.Model):
name = models.CharField(max_length=200)
#create_date = models.DateTimeField('date created')
category = models.CharField(max_length=200, null=True)
app_logo = models.ImageField(upload_to="/root/AR_BROWSER/example/static/uploaded_pics", null=True, blank=True)
user = models.ForeignKey(App_User)
def __unicode__(self):
return self.name
The function in views.py
@csrf_exempt
def create_app(request):
appName = request.POST['name']
user = request.POST['userID']
c = request.POST['category']
i = request.POST['image']
imgdata = base64.b64decode(i)
t = datetime.now()
filename = t.strftime('%Y%m%d%H%M%S.jpg')
with open(filename, 'wb') as f:
f.write(imgdata)
u=App_User.objects.get(id=user)
apps = App.objects.create(name = appName, category=c, user_id = u.id, app_logo=filename)
apps.save()
return HttpResponse("You created %s." % apps.name)