Hi, I like this module but I have one small issue: When an alt_text is provided with the uploaded media (image) the alt_text is not being stored in WordPress.
In class-woocommerce-media-api-controller.php on line 132 the unencoded file binary is added to the requestbody:
$request->set_body($decoded);
From here, $request[‘alt_text’] is not available anymore so it wont be stored.
]]>Using WooCommerce Media API to upload photos and getting what looks like plugin php error (I am not WordPress/PHP knowledgable)
Running WP 5.5.1 , WooCommerce Version 4.4.1, WooCommerce Media API V2.3
Log trace snippet as follows:
D/LoggingInterceptor: request
Sending request https://staging9.online.xxxxx.org/wp-json/wc/v2/media on null Content-Type: application/x-www-form-urlencoded
Authorization: Basic xxxxxxx
{“date”:”2020-09-12T23:58:12.161Z”,”media_attachment”:”……”,”media_path”:”https://staging9.online.xxxxx.org/wp-content/uploads/2020/58/TM-0912-10-01.jpeg”,”media_type”:”image”,”status”:”publish”,”title”:”TM-0912-10-01.jpeg”}
D/LoggingInterceptor: response
Received response for https://staging9.online.xxxxxx.org/wp-json/wc/v2/media in 1476.3ms
server: nginx
date: Sat, 12 Sep 2020 23:59:07 GMT
content-type: application/json; charset=UTF-8
vary: Accept-Encoding
x-robots-tag: noindex
link: <https://staging9.online.householdgoods.org/wp-json/>; rel=”https://api.w.org/”
x-content-type-options: nosniff
access-control-expose-headers: X-WP-Total, X-WP-TotalPages, Link
access-control-allow-headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type
expires: Wed, 11 Jan 1984 05:00:00 GMT
cache-control: no-cache, must-revalidate, max-age=0
x-httpd: 1
host-header: 8441280b0c35cbc1147f8ba998a563a7
x-proxy-cache-info: DT:1
<br />
<b>Warning</b>: Illegal string offset ‘rendered’ in <b>/home/customer/www/staging9.online.xxxxxx.org/public_html/wp-content/plugins/woo-media-api/class-woocommerce-media-api-controller.php</b> on line <b>80</b><br />
<br />
<b>Warning</b>: Cannot modify header information – headers already sent by (output started at /home/customer/www/staging9.online.xxxxx.org/public_html/wp-content/plugins/woo-media-api/class-woocommerce-media-api-controller.php:80) in <b>/home/customer/www/staging9.online.xxxxx.org/public_html/wp-includes/rest-api/class-wp-rest-server.php</b> on line <b>1372</b><br />
{“code”:”rest_upload_sideload_error”,”message”:”Sorry, this file type is not permitted for security reasons.”,”data”:{“status”:500}}
i need use this plugin in my code.
my integration use create a product but not upload product image.
]]>Hi,
I get that filetype is not allowed for a jpeg image.
Do I need to do anything to make it work or is it a parameter to use?
Thanks in advance,
Anders
]]>Hello, thanks for the plugin. When sending files for api, the wrong file type appeared in the media files, solved the problem like this:
In wp-content/plugins/woo-media-api/class-woocommerce-media-api-controller.php
$request->set_body($decoded);
$request->add_header('Content-Disposition', "attachment;filename=\"{$filename}\"");
//BR added
$br_content_type = ( ! empty( $request['mime_type'] ) ? $request['mime_type'] : "image/jpeg" );
$request->remove_header('Content-Type');
$request->add_header('Content-Type', $br_content_type);
// . BR added
$result = $media_controller->create_item( $request );
Now when sending data in addition to fields ‘media_attachment’ and ‘media_path’ can specify ‘mime_type’, for example ‘image/gif’
]]>