header( 'X-WP-Upload-Attachment-ID: ' .
$attachment_id );
} // Include media and image functions to get access to wp_generate_attachment_metadata().
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
/*
* Post-process the upload (create image sub-sizes, make PDF thumbnails, etc.) and insert attachment meta.
* At this point the server may run out of resources and post-processing of uploaded images may fail.
*/
wp_update_attachment_metadata( $attachment_id,
wp_generate_attachment_metadata( $attachment_id,
$file ) );
$response =
$this->
prepare_item_for_response( $attachment,
$request );
$response =
rest_ensure_response( $response );
$response->
set_status( 201
);
$response->
header( 'Location',
rest_url( sprintf( '%s/%s/%d',
$this->namespace,
$this->rest_base,
$attachment_id ) ) );
return $response;
} /**
* Inserts the attachment post in the database. Does not update the attachment meta.
*
* @since 5.3.0
*
* @param WP_REST_Request $request
* @return array|WP_Error
*/