def accept_uploaded_photo(request, album_id):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """
    if request.method == 'POST':
        logid = random.randint(0,1000)
        log.info('[%s] received POST to main multiuploader view' % logid)
        if request.FILES == None:
            return HttpResponseBadRequest('Must have files attached!')

        #getting file data for farther manipulations
        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info ('[%s] Got file: "%s"' % (logid, str(filename)))

        # Write out file to disk as a temp file
        randnumber = logid # use the random number here too
        temp_filename = '%stmp%s_%s' % (settings.TEMP_DIRECTORY,randnumber, filename)
        log.info('[%s] Writing out to: %s' % (logid, temp_filename))
        destination = open(temp_filename, 'wb+')
        if wrapped_file.multiple_chunks():
            for chunk in wrapped_file.chunks():
                destination.write(chunk)
        else:
            destination.write(wrapped_file.read())
        destination.close()

        # Dump out EXIF Tags
#        im = Image.open(temp_filename)
#        if hasattr( im, '_getexif' ):
#            exifinfo = im._getexif()
#            if exifinfo:
#                for tag, value in exifinfo.items():
#                    decoded = ExifTags.TAGS.get(tag, tag)
#                    log.info('Found tag: %s, value: %s' % (decoded,value))

        orientation = None
        date_taken = None
        # Make full size and thumbsize
        try:
            im = Image.open(temp_filename)
        except IOError:
            log.info('[%s] Error opening file %s: %s %s' % (logid, temp_filename, e.errno, e))
            return HttpResponseBadRequest('Could not read file')

        if hasattr( im, '_getexif' ):
            exifinfo = im._getexif()
            if exifinfo:
                for tag, value in exifinfo.items():
                    decoded = ExifTags.TAGS.get(tag, tag)
#                    if decoded != 'MakerNote':
#                        if decoded != 'UserComment':
#                            log.info('Found tag: %s, value: %s' % (decoded,value))
                    if decoded == 'Orientation':
                        orientation = value
                        log.info('[%s] Found tag: %s, value: %s' % (logid,decoded,value))
                    elif decoded == 'DateTime':
                        date_taken =  datetime.strptime(value, "%Y:%m:%d %H:%M:%S")
                        log.info('[%s] Found tag: %s, value: %s, date_taken=%s' % (logid,decoded,value,date_taken))

        # We rotate regarding to the EXIF orientation information
        if orientation:
            if orientation == 1:
                # Nothing
                log.info('[%s] Orientation: No rotation necessary' % logid)
                pass
            elif orientation == 2:
                # Vertical Mirror
                log.info('[%s] Orientation: Vertical flip' % logid)
                im = im.transpose(Image.FLIP_LEFT_RIGHT)
            elif orientation == 3:
                # Rotation 180
                log.info('[%s] Orientation: Rotation 180' % logid)
                im = im.transpose(Image.ROTATE_180)
            elif orientation == 4:
                # Horizontal Mirror
                log.info('[%s] Orientation: Horizontal Mirror' % logid)
                im = im.transpose(Image.FLIP_TOP_BOTTOM)
            elif orientation == 5:
                # Horizontal Mirror + Rotation 270
                log.info('[%s] Orientation: Flip top bottom, rot 270' % logid)
                im = im.transpose(Image.FLIP_TOP_BOTTOM).transpose(Image.ROTATE_270)
            elif orientation == 6:
                # Rotation 270
                log.info('[%s] Orientation: Rotate 270' % logid)
                im = im.transpose(Image.ROTATE_270)
            elif orientation == 7:
                # Vertical Mirror + Rotation 270
                log.info('[%s] Orientation: Flip left right, rotate 270' % logid)
                im = im.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.ROTATE_270)
            elif orientation == 8:
                # Rotation 90
                log.info('[%s] Orientation: Rotate 90' % logid)
                im = im.transpose(Image.ROTATE_90)

        #------------------
        # Save the transposed image to disk
        orig_path = '%stmp%s_mod%s' % (settings.TEMP_DIRECTORY,randnumber, filename)
        # keep 100% fidelity on the image
        try:
            log.info('[%s] Writing corrected photo to path %s' % (logid,orig_path))
            im.save(orig_path, "JPEG", quality=100)
        except IOError:
            log.info('[%s] Error saving file %s: %s %s' % (logid, orig_path, e.errno, e))
            return HttpResponseBadRequest('Could not save file')

        #------------------
        # Save the photo object into the database
        album = Album.objects.get(id=album_id)
        photo = Photo()
        photo.album = album

        log.info('[%s] Determining photo order' % logid)
        #------------------
        # Determine where in the photo order this picture needs to be
        photo.order = 0
        if date_taken:
            photo.photodate = date_taken
            log.info('[%s] Date Taken is %s' % (logid,date_taken))
            # Now try to insert the photo by date taken in the order list
            prev_photo = photo.prev_photo_by_photodate()
            if prev_photo:
                log.info('got prev photo.  id=%s, photodate=%s, order=%s' % (prev_photo.id,prev_photo.photodate,prev_photo.order))
                photo.order = prev_photo.order
            else:
                # First in album
                photo.order = 0
        else:
            # Last in album
            photo.order = album.photo_set.count() + 1

        log.info('[%s] Writing photo entry to database' % logid)
        #------------------
        # Now finally write the entry to the db
        photo.save()
        log.info('[%s] Photo object saved.  id = %s, order = %s' % (logid, photo.id,photo.order))
        #album.reorder_photos()

        log.info('[%s] Attempting to save file %s to django model id %s' % (logid, orig_path, photo.id))
        f = open(orig_path, 'r')
        photo.filename.save('%s.jpg' % photo.id, File(f))
        f.close()

        log.info('[%s] Cleaning up files' % logid)
        #clean up temp file
        unlink(temp_filename)
        unlink(orig_path)

        #settings imports
        file_delete_url = 'multi_delete/'

        thumbnail_options = dict(size=(200, 200), crop=True)
        thumb_url = get_thumbnailer(photo.filename).get_thumbnail(thumbnail_options).url

        #generating json response array
        result = []
        result.append({"name":filename,
                       "size":file_size,
                       "url": thumb_url,
                       "thumbnail_url":thumb_url,
                       "delete_url":'/',
                       "delete_type":"POST",})
        response_data = simplejson.dumps(result)

        #checking for json data type
        #big thanks to Guy Shapiro
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(response_data, mimetype=mimetype)
    else: #GET
        return HttpResponse('Only POST accepted')