why woocommerce api only do not upload images from local computer? [closed]

Because you are just passing the location of the image, not the image itself. So you are basically telling WordPress where your image is located, on your local computer. The server will not be able to access files on your local computer.

Solve it by first uploading the image to WordPress, and then pass in the image ID in your WooCommmerce import script.

Use the script below, to be able to do the following:

'images' => [ file_or_url_to_wordpress_image('C:\Users\579\Desktop\2.1.jpg') ]

What you need to add to your file:

DEFINE('WORDPRESS_BASE_URL', 'https://remote-wordpress-site.com');

// Your WordPress username
DEFINE('WORDPRESS_LOGIN', 'admin');

// Create a new Application Password in dashboard /wp-admin/profile.php
DEFINE('WORDPRESS_APPLICATION_PASSWORD', 'TBIg TthU rJG3 moMe Qjor Vtl2');



/**
 * Takes a file or a url and uploads it to WordPress
 */
function file_or_url_to_wordpress_image($image_path){

    // If the input is a URl, we can process it
    if (filter_var($image_path, FILTER_VALIDATE_URL)) {
        return ['src'=>$image_path];
    }

     // Make sure the image exist
    if (!file_exists($image_path)){return;}

    // Load the image
    $file = file_get_contents( $image_path );

    // Get the filename
    $filename = basename($image_path);

    // Initiate curl.
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt( $ch, CURLOPT_URL, WORDPRESS_BASE_URL .'/wp-json/wp/v2/media/' );
    curl_setopt( $ch, CURLOPT_POST, 1 );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $file );
    curl_setopt( $ch, CURLOPT_HTTPHEADER, [
        "Content-Disposition: form-data; filename=\"$filename\"",
        'Authorization: Basic ' . base64_encode( WORDPRESS_LOGIN. ':' . WORDPRESS_APPLICATION_PASSWORD ),
    ] );
    $result = curl_exec( $ch );
    curl_close( $ch );

    // Decode the response
    $api_response = json_decode($result);

    // Return the ID of the image that is now uploaded to the WordPress site.
    return ['id' => $api_response];
}