Skip to Content
Menu
This question has been flagged
6 Replies
42014 Views

Hello, I am trying to sync odoo with an existing ecommerce platform. Right now, I am trying to upload products from odoo to this platform. In order to upload the product image, I have to send the image url.

I tried to do so through the path /web/image?model=product.template&id={{product.id}}&field=image
But it didn't work, since the url doesn't return the image file.

I also tried to use the path /web/image/product.template/{{product.id}}/image
In this case it didn't work either, because of a 403 - Forbidden error, which I also get when trying to make a GET request using Postman.

Is there a way I can make this URL public? (because the ecommerce I and integrating with, I can't pass access data or such). If not, is there any other URL I might use?

Avatar
Discard
Best Answer

Hi Arthur,

By default the images are stored in the database in a base64 format so they're not really stored as an attachment. If you have the image as an attachment on the product you can create a public URL for it as you can look at the paths from the fields 'local_url' and 'website_url' (from the model ir.attachment) to make a full URL to your image(s). This way you could provide links but then you have to attach the images as an attachment on the products. I've added those two fields to the view from the ir.attachment model so that you can see how the path is built:


If you combine that path (so /web/image/2259?unique=4db4955a92a769b04b4320af6235fdccf8cdf016) with the basic URL of your website (in this case http://422032-11-0-fa8705.runbot15.odoo.com) you'll get a full URL to the image. Being http://422032-11-0-fa8705.runbot15.odoo.com/web/image/2259?unique=4db4955a92a769b04b4320af6235fdccf8cdf016 in this sample. The result after you navigate to this URL is your image:


I can't imagine that you're trying to connect with another ecommerce tool that has literally no way to get values through any protocol from another instance though. Are you really sure you can't? You can use xml-rpc to easily get the base64 images from any product in a matter of seconds.

Regards,
Yenthe

Avatar
Discard
Author

Thanks for your response Yenthe, it helped clarifying things.

I was able to create attachments with the following function:

class ProductTemplate(models.Model):

_inherit = 'product.template'

@api.multi

def create_image_attachment(self, product):

image = self.env['ir.attachment'].create(dict(

datas_fname="Test.png",

name="Image - " + product.name,

datas=product.image,

mimetype='application/png',

res_model='product.template',

res_id=product.id,

))

return image

If I go to the product.template form view, I can download the attachments created and they are download correctly. However, if i try to download the image through the 'image_attachment.local_url', the file I download doesn't have the right name or extension.

Any idea of what I am missing?

Thanks

Author

Just managed to fix it. I just had to mimetype to 'image/jpeg'.

Still, the path provided by .local_url is not public. Is there a way I can make it public?

Author

Just managed to fix it. I just had to mimetype to 'image/jpeg'.

Still, the path provided by .local_url is not public. Is there a way I can make it public?

Trying to import products from odoo export file. Image field is there. Getting error: Found invalid image data, images should be imported as either URLs or base64-encoded data.

Any idea ?

I though that that field is base64 encoded. Am I wrong ?

Best Answer

I managed to solve this issue by doing it manually.. I used a free app called "image from url" and pasted the image url there and then exported the value of the image_from_url field which's the image link!


Avatar
Discard
Best Answer

Currently, to get the product image as url, we could use:

from odoo.tools.image import image_data_uri

product_image = image_data_uri(product.image_1920)

In my case,  product.image_1920 is the column of saved product image, you can replace it with your column to make it work.

Note: after get  product_image, you can see it still look like base64 encrypted format, but it's not, try to paste it to web browser such as Chrome, and you will see the image appear.

Avatar
Discard

I can see the binary of the image...

Best Answer

/

By default the images are **NOT** stored in the database, but in filestore.

In ir_attachment table for images  by  default  type  field  is  set  to  "binary"  and  store_fname field is  set  to  filestore path of the file.

Other behavior  can  be  set  by  config  or  by  addons.

Avatar
Discard
Author Best Answer

I managed to create the attachment and get its .local_url. However the route is also private. Is there a way can make it public?

Avatar
Discard
Best Answer

I have same issue, is there any solution?

Avatar
Discard
Related Posts Replies Views Activity
0
Apr 24
1094
1
Feb 17
22865
2
Dec 16
4546
0
Apr 21
2968
0
Jun 25
2356