def upload_image():
    request_error = ''
    user_id = getUserID('me')
    file = request.files['file']
    if file and allowed_file(file.filename):
        try:
            image_blob = crop_image(Image(file=file)).make_blob()
            image_id = create_image(image_blob, user_id)
            return jsonify(error=None, imageID=str(image_id) + '.' + PROFILE_FORMAT)
        except Exception as e:
            request_error = str(e)
    return jsonify(error=request_error), HTTP_400_BAD_REQUEST
Exemple #2
0
def upload_image():
    request_error = ''
    user_id = getUserID('me')
    file = request.files['file']
    if file and allowed_file(file.filename):
        try:
            image_blob = crop_image(Image(file=file)).make_blob()
            image_id = create_image(image_blob, user_id)
            return jsonify(error=None,
                           imageID=str(image_id) + '.' + PROFILE_FORMAT)
        except Exception as e:
            request_error = str(e)
    return jsonify(error=request_error), HTTP_400_BAD_REQUEST
def upload_image_from_uri():
    user_id = getUserID('me')
    file_location = request.get_json().get('uri')

    # Consider Tornado's async retrival here
    try:
        image_info = urllib2.urlopen(file_location)
    except:
        return jsonify(error='Bad URI'), HTTP_400_BAD_REQUEST

    try:
        image_blob = crop_image(Image(file=image_info)).make_blob()
        image_id = create_image(image_blob, user_id)
        return jsonify(error=None, imageID=str(image_id) + '.' + PROFILE_FORMAT)
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST
Exemple #4
0
def upload_image_from_uri():
    user_id = getUserID('me')
    file_location = request.get_json().get('uri')

    # Consider Tornado's async retrival here
    try:
        image_info = urllib2.urlopen(file_location)
    except:
        return jsonify(error='Bad URI'), HTTP_400_BAD_REQUEST

    try:
        image_blob = crop_image(Image(file=image_info)).make_blob()
        image_id = create_image(image_blob, user_id)
        return jsonify(error=None,
                       imageID=str(image_id) + '.' + PROFILE_FORMAT)
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST