Search code examples
pythoncloudinary

Cloudinary overwrite=false still uploads existing image as a new image


Im using cloudinarys python module. And I'm having some truble with uploading. I'm uploading images from url's, and I dont want to upload an image if it's already uploaded. But as of now the image gets uploaded again but as a new image instead.

imagedata = cloudinary.uploader.upload("cloudinary.uploader.upload("https://akamai.vgc.no/drfront/images/2021/10/01/w=1080;h=710;636204.jpg", folder="vg", overwrite=False)

this is how I'm uploading, and it returnes:

{'asset_id': 'c78b6d70ab1a1b8b7f76f67fa0695b7d',
 'public_id': 'vg/qcn4iq7jmhcohilyhlnv',
 'version': 1633332569,
 'version_id': '54c177500b747897946a8d8388988850',
 'signature': '8d04ad85f08ef00cf531f27f9f53380cccd80c4d',
 'width': 1080,
 'height': 710,
 'format': 'jpg',
 'resource_type': 'image',
 'created_at': '2021-10-04T07:29:29Z',
 'tags': [],
 'bytes': 132493,
 'type': 'upload',
 'etag': '8ddcfbf1ecd556dff38e41c62a201b2c',
 'placeholder': False,
 'url': 'http://res.cloudinary.com/mycloud/image/upload/v1633332569/vg/qcn4iq7jmhcohilyhlnv.jpg',
 'secure_url': 'https://res.cloudinary.com/mycloud/image/upload/v1633332569/vg/qcn4iq7jmhcohilyhlnv.jpg',
 'original_filename': 'w=1080;h=710;636204',
 'api_key': 'mykey'}

If I run the same code again I was under the impression that the image would not reupload but retun the same data with an aditional property existing: true

but it uploads the same immage as a new image in cloudinary and this is the return:

{'asset_id': '498fe21c04b0fec97200c461df586045',
 'public_id': 'vg/pvvwkwqginvouraey9zq',
 'version': 1633333265,
 'version_id': '51c8e37cdceb002ba995ca50a4c88051',
 'signature': 'b451fcfc71e29eeda96cf80af5756fb95077c62c',
 'width': 1080,
 'height': 710,
 'format': 'jpg',
 'resource_type': 'image',
 'created_at': '2021-10-04T07:41:05Z',
 'tags': [],
 'bytes': 132493,
 'type': 'upload',
 'etag': '8ddcfbf1ecd556dff38e41c62a201b2c',
 'placeholder': False,
 'url': 'http://res.cloudinary.com/mycloud/image/upload/v1633333265/vg/pvvwkwqginvouraey9zq.jpg',
 'secure_url': 'https://res.cloudinary.com/mycloud/image/upload/v1633333265/vg/pvvwkwqginvouraey9zq.jpg',
 'original_filename': 'w=1080;h=710;636204',
 'api_key': 'mykey'}

Where am screwing this up?


Solution

  • Without specifying the public_id in your upload - and without applying any upload preset, by default a random filename will be assigned. You can try this code:

    imagedata = cloudinary.uploader.upload("cloudinary.uploader.upload("akamai.vgc.no/drfront/images/2021/10/01/w=1080;h=710;636204.jpg", public_id="vg/qcn4iq7jmhcohilyhlnv", overwrite=False)