Giter Club home page Giter Club logo

m2_api_product_images's Introduction

M2 API Product Image Module

This module is a plugin for Magento 2 that modifies the way to send the product images through the API avoiding the codification of the images in base 64.

History

The idea arose in a project where the client had a catalog of configurable products with 30 or more variations.

This number of variants involved sending to the server about 300 images or more for each configurable product, which resulted in high transmission times and bandwidth consumption when the products of the catalog were updated.

For those who do not know, the Magento 2 API must receive the images encoded in base 64, which Magento then decodes and transforms into a physical file.

The client asked to upload the images to the server via FTP as an alternative.

How does it work

This plugin modifies the behavior of Magento 2 so that through the API, it only receives the name of the image. For everything to work and magic to occur the physical file of the image must be in "pub/media/import"

The plugin verifies that 3 conditions are met:

  1. The "file" field is not empty
  2. The "base64EncodedData" field is empty
  3. An image with the name included in the "file" field exists in the "pub/media/import" folder in the Magento 2 installation.

JSON message example

{
    "product": {
        "sku": "test-product",
        "name": "Test Product",
        "attributeSetId": 4,
        "price": 99,
        "status": 1,
        "typeId": "simple",
        "weight": 1,
        "mediaGalleryEntries": [
            {
                "mediaType": "image",
                "label": "Test Product Image",
                "position": 1,
                "disabled": false,
                "file": "test_image.png",
                "types": [
                    "image",
                    "thumbnail",
                    "small_image"
                ],
                "content": {
                    "base64EncodedData": "",
                    "type": "image/png",
                    "name": "test_image.png"
                }
            }
        ]
    }
}

Donation

If you have used this module consider the possibility of making a donation

paypal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.