首页 > 解决方案 > 通过 vuejs 使用 Gravity 表单 API 以重力形式上传文件

问题描述

我正在使用重力表单 API 来保存表单数据。除文件上传类型数据外,所有表单数据均已存储。如何使用其 API 以重力形式保存文件?

        if (count($_FILES)!=0) {
            foreach ($_FILES as $key => $fileData) {
                $parameters[$key] = $fileData;
            }
        }
        if (count($_POST)!=0) {
            foreach ($_POST as $key => $postData) {
                $parameters[$key] = $postData;
            }
        }

        // Local 
        $consumer_key       = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        $consumer_secret    = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';



        $url = site_url() . '/wp-json/gf/v2/forms/'.$parameters['id'].'/submissions';

        //Use helper to get oAuth authentication parameters in URL.
        //Download helper library from: https://docs.gravityforms.com/wp-content/uploads/2017/01/class-oauth-request.php_.zip
        require( 'class/class-oauth-request.php' );
        $oauth = new OAuth_Request( $url, $consumer_key, $consumer_secret, 'POST', array() );
        $full_url = $oauth->get_url();

        $response = array();
        // Send request
        $response = wp_remote_request( $full_url,
            array('method'  => 'POST',
                'body'    => json_encode($parameters),
                'headers' => array('Content-type' => 'application/json')
            )
        );
        return $response;

// I have also tried with 'headers' => array('Content-type' => 'multipart/form-data')

标签: wordpressapivue.jsfile-uploadgravityforms

解决方案


推荐阅读