Magento2: getting full image URL from rest API: /V1/products/(productID)/media

Created on 4 Dec 2015  路  5Comments  路  Source: magento/magento2

http://mymagentohost.com/index.php/rest/V1/products/(productID)/media

This url is used to get the media for a particular product.

The response does not have the full image URL.

Response:

{
"id": 14,
"media_type": "image",
"label": "",
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"file": "/p/w/pwp_sheet2.jpeg"
}
I am trying to access this URL from a ios app.

Ready for Work

Most helpful comment

Within Magento, you can use \Magento\Catalog\Model\Product\Media\Config::getBaseMediaUrl() to access the media base URL. However, since you are in an app, you will probably have to hardcode the prefix.
If the Webserver document root is configured to the pub/ directory within Magento, the media base URL for you would be http://mymagentohost.com/media/catalog/product.
If the Webserver document root is configured to the Magento base directory, the media base URL for you would be http://mymagentohost.com/pub/media/catalog/product.

All 5 comments

@userException You have the BASE URL because you access the API. Or i'm wrong?

but what should be the prefix for this URL ? if I want to download this image and show this in my app

Within Magento, you can use \Magento\Catalog\Model\Product\Media\Config::getBaseMediaUrl() to access the media base URL. However, since you are in an app, you will probably have to hardcode the prefix.
If the Webserver document root is configured to the pub/ directory within Magento, the media base URL for you would be http://mymagentohost.com/media/catalog/product.
If the Webserver document root is configured to the Magento base directory, the media base URL for you would be http://mymagentohost.com/pub/media/catalog/product.

That said, please refer to the Community Forums or Magento Stack Exchange site for technical questions. This issue tracker is only for bugs proposed changes.
If you think you have encountered a bug, please let us know, otherwise, if the question is answered for you, please close this issue.

Was this page helpful?
0 / 5 - 0 ratings