Pplyz
Pplyz

Reputation: 1

How to get image from odoo12 for external web

I want to get image from Odoo to external web. I tried get any url from controller of odoo but it did not work.

I am using Odoo12 as the web backend for setting values, and there is an external website that will call the API from Odoo for use.

In the database of Odoo, I have more than one, but for this web backend, I use one database. So I thought it had to specify the database name in the URL?

I try call url @http.route '/web/image' from odoo12 but I get error 404: Not Found.

Please advise.

in postman is get

http://localhost:8069/web/image/product.template/32/image

** reponse error.**

{
    "jsonrpc": "2.0",
    "id": null,
    "error": {
        "code": 404,
        "message": "404: Not Found",
        "data": {
            "name": "werkzeug.exceptions.NotFound",
            "debug": "Traceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 654, in _handle_exception\n    return super(JsonRequest, self)._handle_exception(exception)\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 312, in _handle_exception\n    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n  File \"/usr/lib/python3/dist-packages/odoo/tools/pycompat.py\", line 87, in reraise\n    raise value\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 1458, in _dispatch_nodb\n    func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()\n  File \"/usr/lib/python3/dist-packages/werkzeug/routing.py\", line 1581, in match\n    raise NotFound()\nwerkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.\n",
            "message": "404 Not Found: The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.",
            "arguments": [],
            "exception_type": "internal_error"
        },
        "http_status": 404
    }
}

I try more the one url in web controller of Odoo12 but all not work for me

@http.route(['/web/image',
        '/web/image/<string:xmlid>',
        '/web/image/<string:xmlid>/<string:filename>',
        '/web/image/<string:xmlid>/<int:width>x<int:height>',
        '/web/image/<string:xmlid>/<int:width>x<int:height>/<string:filename>',
        '/web/image/<string:model>/<int:id>/<string:field>',
        '/web/image/<string:model>/<int:id>/<string:field>/<string:filename>',
        '/web/image/<string:model>/<int:id>/<string:field>/<int:width>x<int:height>',
      '/web/image/<string:model>/<int:id>/<string:field>/<int:width>x<int:height>/<string:filename>',
        '/web/image/<int:id>',
        '/web/image/<int:id>/<string:filename>',
        '/web/image/<int:id>/<int:width>x<int:height>',
        '/web/image/<int:id>/<int:width>x<int:height>/<string:filename>',
        '/web/image/<int:id>-<string:unique>',
        '/web/image/<int:id>-<string:unique>/<string:filename>',
        '/web/image/<int:id>-<string:unique>/<int:width>x<int:height>',
        '/web/image/<int:id>-<string:unique>/<int:width>x<int:height>/<string:filename>'], type='http', auth="public")
    def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas',
                      filename_field='datas_fname', unique=None, filename=None, mimetype=None,
                      download=None, width=0, height=0, crop=False, related_id=None, access_mode=None,
                      access_token=None, avoid_if_small=False, upper_limit=False, signature=False):

Upvotes: 0

Views: 166

Answers (1)

Tina Sharma
Tina Sharma

Reputation: 77

Hit the session login API before using this product image API. For that, use endpoint as '/web/session/authenticate' and params as 'db_name', 'admin login', 'admin password'.

Upvotes: 0

Related Questions