def upload_image_resize(request):
    options = {'resize': '300x300'}
    try:
        response = Image.upload(PyramidAdapter(request), '/public/', options)
    except Exception:
        response = {'error': str(sys.exc_info()[1])}
    return Response(json.dumps(response))
def upload_image_resize(request):
    options = {'resize': '300x300'}
    try:
        response = Image.upload(DjangoAdapter(request), '/public/', options)
    except Exception:
        response = {'error': str(sys.exc_info()[1])}
    return HttpResponse(json.dumps(response), content_type="application/json")
def upload_image_validation(request):
    def validation(filePath, mimetype):
        with wand.image.Image(filename=filePath) as img:
            if img.width != img.height:
                return False
            return True

    options = {'fieldname': 'myImage', 'validation': validation}
    try:
        response = Image.upload(PyramidAdapter(request), '/public/', options)
    except Exception:
        response = {'error': str(sys.exc_info()[1])}
    return Response(json.dumps(response))
Ejemplo n.º 4
0
def upload_files_validation(request):

    def validation(filePath, mimetype):
        with wand.image.Image(filename=filePath) as img:
            if img.width != img.height:
                return False
        size = os.path.getsize(filePath)
        if size > 10 * 1024 * 1024:
            return False
        return True

    options = {
        'fieldname': 'myImage',
        'validation': validation
    }
    try:
        response = Image.upload(DjangoAdapter(request), '/public/', options)
    except Exception:
        response = {'error': str(sys.exc_info()[1])}
    return HttpResponse(json.dumps(response), content_type="application/json")
def upload_image(request):
    try:
        response = Image.upload(PyramidAdapter(request), '/public/')
    except Exception:
        response = {'error': str(sys.exc_info()[1])}
    return Response(json.dumps(response))