WooCommerce.NET
WooCommerce.NET copied to clipboard
Upload local Media
- Wordpress version : 5.8.2
- WooCommerce version : 6.0.0
- WooCommerce.NET version : 0.8.4
Hello, I try to upload a media from a local file. I already checked the explanation at #419 Unfortunately it doesn't work for me
When I try this code
RestAPI restwp = new RestAPI("https://mywebsite/wp-json/wp/v2/", "my_ck_", "my_cs_"); WPObject wp = new WPObject(restwp); Media Image = await wp.Media.Add("1.jpg", @"Z:\IMAGES\1.jpg");
I receive the following error : WooCommerce.NET.WordPress.v2.Media. Encountered unexpected character 'o'.'
If I understood well, I have to use the OAuth 1.0a authentification in case of JWT for the WP api.
So I tried this as explained on the main page :
RestAPI restwp = new RestAPI("https://mywebsite/wp-json/wp/v2/", "my_ck_", "my_cs_"); restwp.oauth_token = "my_token"; restwp.oauth_token_secret = "my_token_secret"; WPObject wp = new WPObject(restwp); Media Image = await wp.Media.Add("1.jpg", @"Z:\IMAGES\1.jpg");
The error is than different : '{"code":"json_consumer_notfound","message":"Consumer Key is invalid","data":{"status":401}}'
So I add an extra parameter :
RestAPI restwp = new RestAPI("https://mywebsite/wp-json/wp/v2/", "my_ck_", "my_cs_"); restwp.oauth_token = "my_token"; restwp.oauth_token_secret = "my_token_secret"; restwp.WCAuthWithJWT = true; WPObject wp = new WPObject(restwp); Media Image = await wp.Media.Add("1.jpg", @"Z:\IMAGES\1.jpg");
Now the error is : The remote server returned an error: (404) Not Found.
I suppose it's something stupid but I can't find the solution.
Could someone help me or give me a correct sample code to upload an image ?
Thanks in advance,