@frontend.route('/objects/<int:object_id>/files/', methods=['POST'])
@object_permissions_required(Permissions.WRITE)
def post_object_files(object_id):
    check_current_user_is_not_readonly()
    external_link_form = ExternalLinkForm()
    file_form = FileForm()
    if file_form.validate_on_submit():
        file_source = file_form.file_source.data
        if (file_source == 'local'):
            files = flask.request.files.getlist(file_form.local_files.name)
            for file_storage in files:
                file_name = werkzeug.utils.secure_filename(file_storage.filename)
                logic.files.create_database_file(object_id, flask_login.current_user.id, file_name, (lambda stream: file_storage.save(dst=stream)))
            flask.flash(_('Successfully uploaded files.'), 'success')
        else:
            flask.flash(_('Failed to upload files.'), 'error')
    elif external_link_form.validate_on_submit():
        url = external_link_form.url.data
        logic.files.create_url_file(object_id, flask_login.current_user.id, url)
        flask.flash(_('Successfully posted link.'), 'success')
    elif external_link_form.errors:
        flask.flash(_('Failed to post link.'), 'error')
        return flask.redirect(flask.url_for('.object', object_id=object_id, invalid_link=True, _anchor='anchor-post-link'))
    else:
        flask.flash(_('Failed to upload files.'), 'error')
    return flask.redirect(flask.url_for('.object', object_id=object_id))
@frontend.route('/objects/<int:object_id>/files/', methods=['POST'])
@object_permissions_required(Permissions.WRITE)
def post_object_files(object_id):
    check_current_user_is_not_readonly()
    external_link_form = ExternalLinkForm()
    file_form = FileForm()
    if file_form.validate_on_submit():
        file_source = file_form.file_source.data
        if (file_source == 'local'):
            files = flask.request.files.getlist(file_form.local_files.name)
            for file_storage in files:
                file_name = werkzeug.utils.secure_filename(file_storage.filename)
                logic.files.create_database_file(object_id, flask_login.current_user.id, file_name, (lambda stream: file_storage.save(dst=stream)))
            flask.flash(_('Successfully uploaded files.'), 'success')
        else:
            flask.flash(_('Failed to upload files.'), 'error')
    elif external_link_form.validate_on_submit():
        url = external_link_form.url.data
        logic.files.create_url_file(object_id, flask_login.current_user.id, url)
        flask.flash(_('Successfully posted link.'), 'success')
    elif external_link_form.errors:
        flask.flash(_('Failed to post link.'), 'error')
        return flask.redirect(flask.url_for('.object', object_id=object_id, invalid_link=True, _anchor='anchor-post-link'))
    else:
        flask.flash(_('Failed to upload files.'), 'error')
    return flask.redirect(flask.url_for('.object', object_id=object_id))