diff options
Diffstat (limited to 'plugins/jetpack/json-endpoints/class.wpcom-json-api-upload-media-v1-1-endpoint.php')
-rw-r--r-- | plugins/jetpack/json-endpoints/class.wpcom-json-api-upload-media-v1-1-endpoint.php | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-upload-media-v1-1-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-upload-media-v1-1-endpoint.php index f635f451..7aea6949 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-upload-media-v1-1-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-upload-media-v1-1-endpoint.php @@ -1,4 +1,43 @@ <?php + +new WPCOM_JSON_API_Upload_Media_v1_1_Endpoint( array( + 'description' => 'Upload a new piece of media.', + 'allow_cross_origin_request' => true, + 'allow_upload_token_auth' => true, + 'group' => 'media', + 'stat' => 'media:new', + 'min_version' => '1.1', + 'max_version' => '1.1', + 'method' => 'POST', + 'path' => '/sites/%s/media/new', + 'path_labels' => array( + '$site' => '(int|string) Site ID or domain', + ), + + 'request_format' => array( + 'media' => "(media) An array of media to attach to the post. To upload media, the entire request should be multipart/form-data encoded. Accepts jpg, jpeg, png, gif, pdf, doc, ppt, odt, pptx, docx, pps, ppsx, xls, xlsx, key. Audio and Video may also be available. See <code>allowed_file_types</code> in the options response of the site endpoint.<br /><br /><strong>Example</strong>:<br />" . + "<code>curl \<br />--form 'media[]=@/path/to/file.jpg' \<br />-H 'Authorization: BEARER your-token' \<br />'https://public-api.wordpress.com/rest/v1/sites/123/media/new'</code>", + 'media_urls' => "(array) An array of URLs to upload to the post. Errors produced by media uploads, if any, will be in `media_errors` in the response.", + 'attrs' => "(array) An array of attributes (`title`, `description`, `caption` `alt` for images, `artist` for audio, `album` for audio, and `parent_id`) are supported to assign to the media uploaded via the `media` or `media_urls` properties. You must use a numeric index for the keys of `attrs` which follows the same sequence as `media` and `media_urls`. <br /><br /><strong>Example</strong>:<br />" . + "<code>curl \<br />--form 'media[]=@/path/to/file1.jpg' \<br />--form 'media_urls[]=http://example.com/file2.jpg' \<br /> \<br />--form 'attrs[0][caption]=This will be the caption for file1.jpg' \<br />--form 'attrs[1][title]=This will be the title for file2.jpg' \<br />-H 'Authorization: BEARER your-token' \<br />'https://public-api.wordpress.com/rest/v1/sites/123/posts/new'</code>", + ), + + 'response_format' => array( + 'media' => '(array) Array of uploaded media objects', + 'errors' => '(array) Array of error messages of uploading media failures', + ), + + 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/media/new', + 'example_request_data' => array( + 'headers' => array( + 'authorization' => 'Bearer YOUR_API_TOKEN', + ), + 'body' => array( + 'media_urls' => 'https://s.w.org/about/images/logos/codeispoetry-rgb.png', + ), + ) +) ); + class WPCOM_JSON_API_Upload_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint { /** @@ -67,17 +106,17 @@ class WPCOM_JSON_API_Upload_Media_v1_1_Endpoint extends WPCOM_JSON_API_Endpoint } } - // Normal WPCOM upload processing - if ( count( $other_media_files ) > 0 || count( $media_urls ) > 0 ) { - $create_media = $this->handle_media_creation_v1_1( $other_media_files, $media_urls, $media_attrs ); - $media_ids = $create_media['media_ids']; - $errors = $create_media['errors']; - - $media_items = array(); - foreach ( $media_ids as $media_id ) { - $media_items[] = $this->get_media_item_v1_1( $media_id ); - } - } + // Normal WPCOM upload processing + if ( count( $other_media_files ) > 0 || count( $media_urls ) > 0 ) { + $create_media = $this->handle_media_creation_v1_1( $other_media_files, $media_urls, $media_attrs ); + $media_ids = $create_media['media_ids']; + $errors = $create_media['errors']; + + $media_items = array(); + foreach ( $media_ids as $media_id ) { + $media_items[] = $this->get_media_item_v1_1( $media_id ); + } + } if ( count( $media_items ) <= 0 ) { return $this->api->output_early( 400, array( 'errors' => $errors ) ); |