示例#1
0
def upload_avatar(request):
    print('xxxx')
    avatar_file = request.FILES.get('avatar')
    print('你来了?')
    print(avatar_file)
    filename, filepath = save_avatar(request.uid, avatar_file)  # 文件保存到本地
    print(filename, filepath)
    avatar_url = upload_to_qiniu(filename, filepath)  # 文件上传到七牛
    User.objects.filter(id=request.uid).update(avatar=avatar_url)  # 保存 URL
    # os.remove(filepath)  # 删除本地临时文件
    # 删除旧的缓存
    key = keys.PROFILE_K % request.uid
    model_user_key = 'Model-User-%s' % (request.uid)
    model_profile_key = 'Model-Profile-%s' % (request.uid)
    rds.delete(key)
    rds.delete(model_user_key)
    rds.delete(model_profile_key)
    return render_json()
# http://img.jj20.com/up/allimg/tx06/07112019921.jpg
示例#2
0
def upload_avatar(uid, avatar_file):
    filename, filepath = save_avatar(uid, avatar_file)  # 文件保存到本地
    avatar_url = upload_to_qiniu(filename, filepath)  # 文件上传到七牛
    User.objects.filter(id=uid).update(avatar=avatar_url)  # 保存 URL
    os.remove(filepath)  # 删除本地临时文件
示例#3
0
def upload_avatar(uid, avatar_file):
    filename, filepath = save_avatar(uid, avatar_file)
    avatar_url = upload_to_qiniu(filename, filepath)
    User.objects.filter(id=uid).update(avatar=avatar_url)
    os.remove(filepath)