WooCommerce REST API。从另一台服务器上传WebP文件时校验和错误

发布于 2025-02-12 17:44:33 字数 767 浏览 0 评论 0原文

我正在向WooCommerce REST API发送邮政请求,以创建具有图像的产品( https://cdn.beymen.com/productimages/opfgmmmg.0cz_img_01_21100856666379.jpg )看到它实际上是WebP文件)。

当我上传另一个以WebP结尾的WebP映像时,它正在工作。但是,当我将URL上传到上方时,我会发现此错误。

{'code':'woocommerce_product_image_upload_error','消息':'„„„ woocommerce_image_image_upload_error':'„„„„ woocommerce_image_image_upload_error':'„„„„ woocommerce_image_image_upload_error':'。 https://cdn.beymen.com/productimages/opfgmmmg.0cz_img_01_2110085666379.jpg。 →函数(4572785D201F809BCDC2A9B7BF82E305)的校验和不匹配预期的校验和值(feb886e9d82201b5189e121d121d121da761451d)。

I am sending a post request to woocommerce REST API to create a product with an image on it (https://cdn.beymen.com/productimages/opfgmmmg.0cz_IMG_01_2110085666379.jpg) (the extension of the file in the url is jpg but when you download it you can see that it is actually webP file).

When I upload another webP images that actually ends with webp it is working. but when I am uploading the url above I am gettin this error.

{'code': 'woocommerce_product_image_upload_error', 'message': 'Ошибка дистанционного получения изображения https://cdn.beymen.com/productimages/opfgmmmg.0cz_IMG_01_2110085666379.jpg. Ошибка: The checksum of the file (4572785d201f809bcdc2a9b7bf82e305) does not match the expected checksum value (feb886e9d82201b5189e121da761451d).', 'data': {'status': 400}}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风情万种。 2025-02-19 17:44:33

您可以使用以下片段来修复它

add_filter('wp_handle_sideload_prefilter', 'real_image_ext');

function real_image_ext($file){
    $real_mime = wp_get_image_mime( $file['tmp_name'] );
    $mime_to_ext = apply_filters(
        'getimagesize_mimes_to_exts',
        array(
            'image/jpeg' => 'jpg',
            'image/png'  => 'png',
            'image/gif'  => 'gif',
            'image/bmp'  => 'bmp',
            'image/tiff' => 'tif',
            'image/webp' => 'webp',
        )
    );
    if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
        $file['name'] = pathinfo($file['name'], PATHINFO_FILENAME) . '.' . $mime_to_ext[ $real_mime ];
    }
    return $file;
}

You can fix it using the following snippet

add_filter('wp_handle_sideload_prefilter', 'real_image_ext');

function real_image_ext($file){
    $real_mime = wp_get_image_mime( $file['tmp_name'] );
    $mime_to_ext = apply_filters(
        'getimagesize_mimes_to_exts',
        array(
            'image/jpeg' => 'jpg',
            'image/png'  => 'png',
            'image/gif'  => 'gif',
            'image/bmp'  => 'bmp',
            'image/tiff' => 'tif',
            'image/webp' => 'webp',
        )
    );
    if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
        $file['name'] = pathinfo($file['name'], PATHINFO_FILENAME) . '.' . $mime_to_ext[ $real_mime ];
    }
    return $file;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文