• Resolved frances2823

    (@frances2823)


    Hello,

    I manage a woocommerce website with the Woo Rest API.
    WP and Woo are up to date and using the last Woo Rest API.

    Everything is working well.

    My main problem is when I update a product, the image is not overwriting the existing one. It copy a new file with a “-number” at the end of the file and keeping the old one. It’s ok and quite secure but it’s a big problem for disk space.

    In wordpress, we already have for one uploaded image, 3 thumbs : so 4 files.

    And in my case, I have this 4 files created for each catalog update. So the upload folder become so huge, that it can crash my server because of lack of space.

    How can we properly update a product without having copys of the image, or delete the old image and keep the newest by the Woo Rest API ?

    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • Mirko P.

    (@rainfallnixfig)

    Hey @frances2823,

    Can you share a sample of the call that is being sent to WooCommerce via the REST API when you update the product image? Did you try to include the ID in the images array? I believe this will force it to overwrite.

    Thanks.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    Thread Starter frances2823

    (@frances2823)

    Sorry for the late,

    here is a copy of my json update :

    [{"id":1945,"name":"my_product","type":"simple","status":"publish","catalog_visibility":"visible","images":[{"src":"http:\/\/mywebsite.com\/client\/folder\/upload_article_web\/img.jpg"}],"featured":false,"description":"","short_description":"","sku":"4765812","regular_price":"8","sale_price":"","date_on_sale_from":"","date_on_sale_to":"","tax_status":"taxable","tax_class":"1","manage_stock":true,"stock_quantity":-555,"backorders":"yes","reviews_allowed":false,"attributes":[{"name":"La portion","options":["250g"],"visible":true},{"name":"Prix unitaire","options":["32 Euro \/ Kilogramme"],"visible":true},{"name":"Vendu sous vide","options":["OUI"],"visible":true},{"name":"Conseils de pr\u00e9paration","options":[],"visible":false},{"name":"Conseils de conservation","options":[],"visible":false},{"name":"Trucs et astuces","options":[],"visible":false},{"name":"Ingr\u00e9dient","options":[],"visible":false},{"name":"Info Produit","options":[],"visible":false},{"name":"Label2","options":[],"visible":false},{"name":"Producteur","options":[],"visible":false},{"name":"Label1","options":[],"visible":false}],"categories":[{"id":1247}],"_fields":["id","_method","name","type","status","featured","catalog_visibility","description","short_description","sku","regular_price","sale_price","date_on_sale_from","date_on_sale_to","tax_status","tax_class","manage_stock","stock_quantity","backorders","reviews_allowed","attributes","images","categories"]}]

    here img.jpg will become “img-2.jpg” and keeping “img.jpg” on the server.

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there @frances2823,

    Thank you very much for providing that. I see in your JSON, you have the images array as:

    "images":
            [
                {
                    "src": "https://mywebsite.com/client/folder/upload_article_web/img.jpg"
                }
            ],

    @rainfallnixfig mentioned that including the ID in the images array may force it to update instead — did you try that?
    https://woocommerce.github.io/woocommerce-rest-api-docs/#product-properties

    As shown in the example call for updating products in the REST API docs here, it lists the ID in the array as well:
    https://woocommerce.github.io/woocommerce-rest-api-docs/#update-a-product

    "images": [
        {
          "id": 792,
          "date_created": "2017-03-23T14:01:13",
          "date_created_gmt": "2017-03-23T20:01:13",
          "date_modified": "2017-03-23T14:01:13",
          "date_modified_gmt": "2017-03-23T20:01:13",
          "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg",
          "name": "",
          "alt": ""
        }
      ],

    Please give that a try, and let us know how it goes. Thank you!

    Thread Starter frances2823

    (@frances2823)

    thanks I will try it !

    Thread Starter frances2823

    (@frances2823)

    Awesome, that’s it, if I put the Image ID in the json, it doesn’t create a new copy ?? ??
    Thanks a lot @kellymetal !!

    • This reply was modified 3 years, 1 month ago by frances2823.
    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there @frances2823,

    Very glad to hear that did the trick!!

    It was @rainfallnixfig’s suggestion though, so all thanks to them! ??

    Take care, and have a good one!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Update a product image via woo rest API’ is closed to new replies.