Esempio n. 1
0
def upload():
    try:
        uploaded_files = request.files.getlist("files[]")
        filenames = img_upload(uploaded_files)
        if len(filenames) > 0:
            urls = ['/images/'+x for x in filenames]
            return prep_response({"files_url": urls})
    except:
        pass

    return prep_response('Upload error', 500)
Esempio n. 2
0
def upload_icon():
    try:
        user = authorized_user()
        uploaded_files = request.files.getlist("files[]")
        if len(uploaded_files) > 1:
            uploaded_files = [uploaded_files[-1]]
        filenames = img_upload(uploaded_files)
        if len(filenames) > 0:
            # removed old image
            if user['user_icon'] != 'default.png':
                os.remove(os.path.join(app.config['UPLOAD_FOLDER'], user['user_icon']))
            DOMAIN['users'].patch(user['_id'], {'user_icon': filenames[-1]})
            return prep_response({})
    except Exception as e:
        logger.debug(str(e))

    return prep_response('Upload error', 500)