@csrf_exempt<EOL>def upload_photos(request):
upurl = '<STR_LIT>'<EOL>if request.FILES.get("<STR_LIT>"):<EOL><INDENT>f = request.FILES.get("<STR_LIT>")<EOL>obj = Image_File.objects.create(upload=f, is_image=True)<EOL>obj.save()<EOL>thumbnail_name = '<STR_LIT>' + f.name<EOL>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>image_file = requests.get(obj.upload.url, stream=True)<EOL>with open(thumbnail_name, '<STR_LIT:wb>') as destination:<EOL><INDENT>for chunk in image_file.iter_content():<EOL><INDENT>destination.write(chunk)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>image_file = f<EOL>with open(thumbnail_name, '<STR_LIT:wb>') as destination:<EOL><INDENT>for chunk in image_file.chunks():<EOL><INDENT>destination.write(chunk)<EOL><DEDENT><DEDENT><DEDENT>im = Image.open(destination.name)<EOL>size = (<NUM_LIT>, <NUM_LIT>)<EOL>im.thumbnail(size)<EOL>im.save(thumbnail_name)<EOL>with open(thumbnail_name, '<STR_LIT:rb>') as imdata:<EOL><INDENT>obj.thumbnail.save(thumbnail_name, File(imdata))<EOL><DEDENT>obj.save()<EOL>os.remove(os.path.join(settings.BASE_DIR, thumbnail_name))<EOL>upurl = "<STR_LIT:/>" + obj.upload.url<EOL><DEDENT>return HttpResponse(<EOL>"""<STR_LIT>""".format(request.GET['<STR_LIT>'], upurl)<EOL>)<EOL>
takes all the images coming from the redactor editor and
stores it in the database and returns all the files