Ejemplo n.º 1
0
def file_uploader(request):
    try:
        blob = request.FILES['img']
        url = qiniu_upload_fileobj(blob, bucket, '.png')
        # md5 = md5_file(blob)
        md5 = 'hash'
        obj, is_new = models.Storage.objects.get_or_create(
            domain=domain,
            url=url,
            hash=md5
        )

        return JsonResponseSuccess(url=obj.path, pk=obj.pk)
    except Exception, e:
        return JsonResponseFailure(reason=str(e))
Ejemplo n.º 2
0
def file_uploader(request, *args, **kwargs):
    url = qiniu_upload_fileobj(request.FILES['img'], 'missuor', '.png')
    with_domain = request.POST.get('full_path', False)
    if with_domain:
        url = '%s/%s' % (domain, url)
    return JsonResponseSuccess(url=url)