wordpress - 通过 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')
解决方案
推荐阅读
- google-app-engine - 如何通过 GWT RPC 返回大数据
- python-3.x - 如何将 UTC 日期时间对象转换为本地时间元组?
- java - GWT 的奇怪未捕获错误,UmbrellaException
- python - 我正在尝试抓取一个网站。但是我在python中有一些错误
- ruby-on-rails - 如何从按会话过滤的模型中计算 view_number?
- python - 如何使用特定条件控制用户输入
- python - Keras模型的训练后全整数量化
- javascript - AWS lambda 的笑话单元测试
- sql - SQL:WITH子句如何引用column_name
- c++ - 在c ++中构造调用new in loop而不是new []的数组元素是否合法?