Clear uploaded file and allow write to it.
    Only for not too big files!!!
    Also can clear simple opened file.
    Examples:
        truncate_file(request.FILES['file'])

        with open('/tmp/file', 'rb+') as f:
            truncate_file(f)

def truncate_file(f):
    """
    Clear uploaded file and allow write to it.
    Only for not too big files!!!
    Also can clear simple opened file.
    Examples:
        truncate_file(request.FILES['file'])

        with open('/tmp/file', 'rb+') as f:
            truncate_file(f)
    """
    if isinstance(f, InMemoryUploadedFile):
        f.file = StringIO()
    else:
        f.seek(0)
        f.truncate(0)