I am developing API for Wordpress using REST-API. Now I am stuck at one point where I am not able to develop the API through which I can upload the image to wordpress using Rest API.
I am using Postman to test API developed for my website
I am developing API for Wordpress using REST-API. Now I am stuck at one point where I am not able to develop the API through which I can upload the image to wordpress using Rest API.
I am using Postman to test API developed for my website
You can upload images just like your normal PHP/Wordpress file uploads.
Reference =>
wp_handle_upload
$mimes = array(
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'png' => 'image/png',
'tif' => 'image/tiff',
'tiff' => 'image/tiff'
);
$overrides = array(
'mimes' => $mimes,
'test_form' => false
);
$upload = wp_handle_upload( $_FILES['YOUR_INPUT_FILE_NAME_HERE'], $overrides );
remove_filter( 'upload_dir', array($this, 'change_upload_dir') );
if ( isset( $upload['error'] ) ){
// SOME UPLOAD ERROR OCCURED
} else {
// File uploaded successfully.
$uploadedFileURL = $upload['url'];
$uploadedFileName = basename($upload['url']);
}
And you can attach files in postman following way.