after many times I’m searching on the Internet.
I find the function to upload new media with REST API WP with CURL in PHP.
but, I don’t know how to convert it to POSTMAN to test faster.
this’s my PHP Code worked.
$path = 'D:WALLPAPERlandscape_natural_Beautiful_mountain_scenery_house_green_2560x1600.jpg';
$request_url = 'http://bdshuuloc.phongmy.net/wp-json/wp/v2/media';
$image = file_get_contents( $path );
$mime_type = mime_content_type( $path );
$user = 'thienduc';
$pass = '@#ThienDuc#@';
$api = curl_init();
curl_setopt( $api, CURLOPT_URL, $request_url );
curl_setopt( $api, CURLOPT_POST, 1 );
curl_setopt( $api, CURLOPT_POSTFIELDS, $image );
curl_setopt( $api, CURLOPT_HTTPHEADER, array( 'Content-Type: ' . $mime_type, 'Content-Disposition: attachment; filename="' . basename($path) . '"' ) );
curl_setopt( $api, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $api, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt( $api, CURLOPT_USERPWD, $user . ':' . $pass );
$result = curl_exec( $api );
curl_close( $api );
$rs = json_decode( $result );
print_r( $rs);
And this’s config on POSTMAN: => https://prnt.sc/10cifq3
Basic Auth is ok. I can delete and update, add a new post success
how to convert or add some condition in POSTMAN to work for UPLOAD MEDIA with REST API, everybody.
Thanks 🙂
2
Answers
Here is the way to copy HTTP requests from Developer tools to Postman:
In case anyone today is still looking for an answer, the answer in this post helped me:
https://wordpress.stackexchange.com/questions/294725/wordpress-rest-upload-media
Headers:
Body: