Ejemplo n.º 1
0
def UploadPic(request):
    """upload pic to qiniu."""
    if request.method == 'POST':
        img = request.FILES.get('Filedata', None)
        type = request.POST.get('type', None)
        if type:
            qn = SuperQiniu(img, w=800, h=520)
        else:
            qn = SuperQiniu(img)
        qn.uploadFile()
        remote_url = qn.downloadFile()
        key = qn.getKey()
        pic = Pic.objects.create(img=remote_url, key=key)
        return ajax.ajax_ok({'id':pic.id, 'url':pic.img, 'key':key})
Ejemplo n.º 2
0
def UploadPic(request):
    """upload pic to qiniu."""
    if request.method == 'POST':
        img = request.FILES.get('Filedata', None)
        type = request.POST.get('type', None)
        if type:
            qn = SuperQiniu(img, w=800, h=520)
        else:
            qn = SuperQiniu(img)
        qn.uploadFile()
        remote_url = qn.downloadFile()
        key = qn.getKey()
        pic = Pic.objects.create(img=remote_url, key=key)
        return ajax.ajax_ok({'id': pic.id, 'url': pic.img, 'key': key})
Ejemplo n.º 3
0
def setAvatar(request):
    """更改头像"""
    context = {}
    user = request.user
    context['form'] = AvatarForm()
    context['pic'] = ['/site_media/avatar/%s.jpg' % str(i) for i in range(1, 36)]
    if request.method == 'POST':
        form = AvatarForm(request.POST, request.FILES)
        if form.is_valid():
            avatar = request.FILES['avatar']
            qiniu = SuperQiniu(avatar)            # 实例化超级七牛类
            qiniu.uploadFile()                    # 上传文件
            url = qiniu.downloadFile()              # 返回url
            user.avatar = url
            user.save()
            # return HttpResponseRedirect('/manage/success/?url=%s' % str(request.path))
        context['form'] = form
    return render(request, 'manager/user/avatar.html', context)
Ejemplo n.º 4
0
def setAvatar(request):
    """更改头像"""
    context = {}
    user = request.user
    context['form'] = AvatarForm()
    context['pic'] = [
        '/site_media/avatar/%s.jpg' % str(i) for i in range(1, 36)
    ]
    if request.method == 'POST':
        form = AvatarForm(request.POST, request.FILES)
        if form.is_valid():
            avatar = request.FILES['avatar']
            qiniu = SuperQiniu(avatar)  # 实例化超级七牛类
            qiniu.uploadFile()  # 上传文件
            url = qiniu.downloadFile()  # 返回url
            user.avatar = url
            user.save()
            # return HttpResponseRedirect('/manage/success/?url=%s' % str(request.path))
        context['form'] = form
    return render(request, 'manager/user/avatar.html', context)