Edit:
Please use the answer chosen above - the code below works for the question but it is not recommended.
The image file you are uploading can be found in:
request.FILES['image'] # assuming input name is called 'image'
It does not return you an Image object, but rather a UploadedFile object. You can read this portion of the docs (I am assuming you are using Django 1.3.x): https://docs.djangoproject.com/en/1.3/topics/http/file-uploads/#handling-uploaded-files
It covers the fields and methods available in the UploadedFile object, and also a common way to handle file uploads manually. You can use the same method to write the image file to a file object and then saving it to your ImageField.
The following code should work, but it is not safe code. I am assuming you are using *nix machine, if not, save the destination file somewhere else.
@csrf_exempt
def saveImage(request):
# warning, code might not be safe
up_file = request.FILES['image']
destination = open('/tmp/' + up_file.name , 'wb+')
for chunk in up_file.chunks():
destination.write(chunk)
destination.close()
img = someImage()
img.image.save(up_file.name, File(open('/tmp/' + up_file.name, 'r')))
img.save()
# return any response you want after this
Other things to take note: Make sure you form has the following attribute for it to work:
<form enctype="multipart/form-data" ... >
I don't recall this usage being normal, but really, Forms are recommended.