我已扩展WP API 插件提供可以处理文档的API。
Routes
public function register_routes($routes)
{
$documents_routes = array(
\'/v1/documents\' => array(
array(array($this, \'create_document\'), WP_JSON_Server::CREATABLE),
)
);
$new_routes = array_merge($routes, $documents_routes);
return $new_routes;
}
callback function
public function create_document($data, $_files = null){
if(!empty($_files)) {
// process file
}
// how to retrieve
}
Request
POST /api/v1/documents/ HTTP/1.1
Host: localhost
Cache-Control: no-cache
Postman-Token: d5277e1c-12ac-309a-034f-135173b7c7f2
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="doc_id"
3268360
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="PINS REST API Documentation v1.2.doc"
Content-Type: application/msword
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="case_reference"
EN0102234
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="author"
Ghazanfar
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="stage"
1
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="category"
Application
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="type"
Document
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="description"
This is test document
----WebKitFormBoundary7MA4YWxkTrZu0gW
The Problem
我有一些属性,如doc\\u id、case\\u reference、description、author、size等,这些属性将随文件一起传递给api。
现在的问题是,如果使用内容类型:表单数据,我希望能够检索所有数据。高效检索回调函数中传递的所有数据的最佳方法是什么?