WooCommerce.NET icon indicating copy to clipboard operation
WooCommerce.NET copied to clipboard

Product Image

Open facundovillalba38 opened this issue 3 years ago • 4 comments

Hello !

There is a way to upload an image to the product from a local path instead an url?

Because i retrieve the image i need to use from a database.

Thank you

facundovillalba38 avatar Mar 24 '21 18:03 facundovillalba38

I had the same problem, but solved it, this is how I did it. I got the image from the database and stored it in a MemoryStream variable, I used SSH (ScpClient) to upload the picture to the webpage's server and I made sure that I could see the image from my browser if I typed in the URL (pathway to the picture). If that worked, I could use THAT URL for my ProductImage source.

promartin avatar Mar 25 '21 10:03 promartin

Please check #419

XiaoFaye avatar Mar 26 '21 10:03 XiaoFaye

Hi I have a simple solution for this: First, we need to clone https://github.com/WP-API/Basic-Auth on Wordpress wp-content/plugins folder and activate it on Wordpress admin. Second, we can add the image URL of the product using Wordpress and getting the image URL to use on Woocommerce.

var client = new RestClient(" https://YOURSITE.COM/wp-json/wp/v2/media");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Basic ********************************");
            request.AddHeader("Cookie", "PHPSESSID=3.....5");
            request.AddFile("file", "H:\\Pictures\\photo_2021-05-28_14-36-44.jpg");
            request.AddParameter("title", "hellowabba");
            request.AddParameter("caption", "darkness");
            IRestResponse response = client.Execute(request);

            Console.WriteLine(response.Content);//this is our Wordpress JSON response which have the URL of the uploaded image

And then using the URL on WoocommerceNet when adding/updating the image of the product.

abrahambrons avatar Jun 28 '21 19:06 abrahambrons

I'm using your solution, but i have a question, can i submit a byte array as image?

pauloholiver avatar Jan 14 '22 15:01 pauloholiver