def update_metadata(metadata, public_ids, **options): """ Populates metadata fields with the given values. Existing values will be overwritten. Any metadata-value pairs given are merged with any existing metadata-value pairs (an empty value for an existing metadata field clears the value) :param metadata: A list of custom metadata fields (by external_id) and the values to assign to each of them. :param public_ids: An array of Public IDs of assets uploaded to Cloudinary. :param options: Options such as *resource_type* (the type of file. Default: image. Valid values: image, raw, or video) and *type* (The storage type. Default: upload. Valid values: upload, private, or authenticated.) :return: A list of public IDs that were updated :rtype: mixed """ params = { "timestamp": utils.now(), "metadata": utils.encode_context(metadata), "public_ids": utils.build_array(public_ids), "type": options.get("type") } return call_api("metadata", params, **options)
def explicit(public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "public_id": public_id, "callback": options.get("callback"), "headers": utils.build_custom_headers(options.get("headers")), "eager": utils.build_eager(options.get("eager")), "eager_notification_url": options.get("eager_notification_url"), "eager_async": options.get("eager_async"), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])), "face_coordinates": utils.encode_double_array(options.get("face_coordinates")), "custom_coordinates": utils.encode_double_array(options.get("custom_coordinates")), "invalidate": options.get("invalidate"), "context": utils.encode_dict(options.get("context")), "responsive_breakpoints": utils.generate_responsive_breakpoints_string( options.get("responsive_breakpoints")) } return call_api("explicit", params, **options)
def setUp(self): self.timestamp_tag = "api_test_tag_{0}".format(utils.now()) if ApiTest.initialized: return ApiTest.initialized = True cloudinary.reset_config() if not cloudinary.config().api_secret: return try: api.delete_resources(["api_test", "api_test2", "api_test3"]) except Exception: pass for transformation in ["api_test_transformation", "api_test_transformation2", "api_test_transformation3"]: try: api.delete_transformation(transformation) except Exception: pass for transformation in ["api_test_upload_preset", "api_test_upload_preset2", "api_test_upload_preset3", "api_test_upload_preset4"]: try: api.delete_upload_preset(transformation) except Exception: pass for id in ["api_test", "api_test2"]: uploader.upload("tests/logo.png", public_id=id, tags=["api_test_tag", self.timestamp_tag], context="key=value", eager=[{"width": 100, "crop": "scale"}])
def upload_large_part(file, **options): """ Upload large raw files. Note that public_id should include an extension for best results. """ params = { "timestamp": utils.now(), "type": options.get("type"), "backup": options.get("backup"), "final": options.get("final"), "part_number": options.get("part_number"), "upload_id": options.get("upload_id"), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])), "public_id": options.get("public_id") } return call_api("upload_large", params, resource_type="raw", file=file, **options)
def destroy(public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "invalidate": options.get("invalidate"), "public_id": public_id } return call_api("destroy", params, **options)
def call_tags_api(tag, command, public_ids = [], **options): params = { "timestamp": utils.now(), "tag": tag, "public_ids": utils.build_array(public_ids), "command": command, "type": options.get("type") } return call_api("tags", params, **options)
def call_context_api(context, command, public_ids=None, **options): params = { "timestamp": utils.now(), "context": utils.encode_context(context), "public_ids": utils.build_array(public_ids), "command": command, "type": options.get("type") } return call_api("context", params, **options)
def explode(public_id, **options): params = { "timestamp": utils.now(), "public_id": public_id, "format": options.get("format"), "notification_url": options.get("notification_url"), "transformation": utils.generate_transformation_string(**options)[0] } return call_api("explode", params, **options)
def call_tags_api(tag, command, public_ids=None, **options): params = { "timestamp": utils.now(), "tag": tag, "public_ids": utils.build_array(public_ids), "command": command, "type": options.get("type") } return call_api("tags", params, **options)
def rename(from_public_id, to_public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "overwrite": options.get("overwrite"), "from_public_id": from_public_id, "to_public_id": to_public_id } return call_api("rename", params, **options)
def generate_sprite(tag, **options): params = { "timestamp": utils.now(), "tag": tag, "async": options.get("async"), "notification_url": options.get("notification_url"), "transformation": utils.generate_transformation_string(fetch_format=options.get("format"), **options)[0] } return call_api("sprite", params, **options)
def multi(tag, **options): params = { "timestamp": utils.now(), "tag": tag, "format": options.get("format"), "async": options.get("async"), "notification_url": options.get("notification_url"), "transformation": utils.generate_transformation_string(**options)[0] } return call_api("multi", params, **options)
def explicit(public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "public_id": public_id, "callback": options.get("callback"), "headers": build_custom_headers(options.get("headers")), "eager": build_eager(options.get("eager")), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"]))} return call_api("explicit", params, **options)
def upload_large_part(file, **options): """ Upload large raw files. Note that public_id should include an extension for best results. """ params = { "timestamp": utils.now(), "type": options.get("type"), "backup": options.get("backup"), "final": options.get("final"), "part_number": options.get("part_number"), "upload_id": options.get("upload_id"), "public_id": options.get("public_id") } return call_api("upload_large", params, resource_type="raw", file=file, **options)
def explicit(public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "public_id": public_id, "callback": options.get("callback"), "headers": utils.build_custom_headers(options.get("headers")), "eager": utils.build_eager(options.get("eager")), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])), "face_coordinates": utils.encode_double_array(options.get("face_coordinates")), "custom_coordinates": utils.encode_double_array(options.get("custom_coordinates"))} return call_api("explicit", params, **options)
def rename(from_public_id, to_public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "overwrite": options.get("overwrite"), "invalidate": options.get("invalidate"), "from_public_id": from_public_id, "to_public_id": to_public_id, "to_type": options.get("to_type"), "context": options.get("context"), "metadata": options.get("metadata") } return call_api("rename", params, **options)
def explicit(public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "public_id": public_id, "callback": options.get("callback"), "headers": utils.build_custom_headers(options.get("headers")), "eager": utils.build_eager(options.get("eager")), "eager_notification_url": options.get("eager_notification_url"), "eager_async": options.get("eager_async"), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])), "face_coordinates": utils.encode_double_array(options.get("face_coordinates")), "custom_coordinates": utils.encode_double_array(options.get("custom_coordinates"))} return call_api("explicit", params, **options)
def explicit(public_id, **options): params = { "timestamp": utils.now(), "type": options.get("type"), "public_id": public_id, "callback": options.get("callback"), "headers": utils.build_custom_headers(options.get("headers")), "eager": utils.build_eager(options.get("eager")), "eager_notification_url": options.get("eager_notification_url"), "eager_async": options.get("eager_async"), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])), "face_coordinates": utils.encode_double_array(options.get("face_coordinates")), "custom_coordinates": utils.encode_double_array(options.get("custom_coordinates")), "invalidate": options.get("invalidate"), "context": utils.encode_dict(options.get("context")), "responsive_breakpoints": utils.generate_responsive_breakpoints_string(options.get("responsive_breakpoints")), } return call_api("explicit", params, **options)
def build_upload_params(**options): params = {"timestamp": utils.now(), "transformation": utils.generate_transformation_string(**options)[0], "public_id": options.get("public_id"), "callback": options.get("callback"), "format": options.get("format"), "type": options.get("type"), "backup": options.get("backup"), "faces": options.get("faces"), "image_metadata": options.get("image_metadata"), "exif": options.get("exif"), "colors": options.get("colors"), "headers": build_custom_headers(options.get("headers")), "eager": build_eager(options.get("eager")), "use_filename": options.get("use_filename"), "invalidate": options.get("invalidate"), "notification_url": options.get("notification_url"), "eager_notification_url": options.get("eager_notification_url"), "eager_async": options.get("eager_async"), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"]))} return params
def create_slideshow(**options): """ Creates auto-generated video slideshows. :param options: The optional parameters. See the upload API documentation. :return: a dictionary with details about created slideshow """ options["resource_type"] = options.get("resource_type", "video") params = {param_name: options.get(param_name) for param_name in _SLIDESHOW_PARAMS} serialized_params = { "timestamp": utils.now(), "transformation": build_eager(options.get("transformation")), "manifest_transformation": build_eager(options.get("manifest_transformation")), "manifest_json": options.get("manifest_json") and utils.json_encode(options.get("manifest_json")), "tags": options.get("tags") and utils.encode_list(utils.build_array(options["tags"])), } params.update(serialized_params) return call_api("create_slideshow", params, **options)
def build_upload_params(**options): params = {"timestamp": utils.now(), "transformation": utils.generate_transformation_string(**options)[0], "public_id": options.get("public_id"), "callback": options.get("callback"), "format": options.get("format"), "type": options.get("type"), "backup": options.get("backup"), "faces": options.get("faces"), "image_metadata": options.get("image_metadata"), "exif": options.get("exif"), "colors": options.get("colors"), "headers": build_custom_headers(options.get("headers")), "eager": build_eager(options.get("eager")), "use_filename": options.get("use_filename"), "unique_filename": options.get("unique_filename"), "discard_original_filename": options.get("discard_original_filename"), "invalidate": options.get("invalidate"), "notification_url": options.get("notification_url"), "eager_notification_url": options.get("eager_notification_url"), "eager_async": options.get("eager_async"), "proxy": options.get("proxy"), "folder": options.get("folder"), "overwrite": options.get("overwrite"), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])), "allowed_formats": options.get("allowed_formats") and ",".join(utils.build_array(options["allowed_formats"])), "face_coordinates": utils.encode_double_array(options.get("face_coordinates")), "context": utils.encode_dict(options.get("context")), "moderation": options.get("moderation"), "raw_convert": options.get("raw_convert"), "ocr": options.get("ocr"), "categorization": options.get("categorization"), "detection": options.get("detection"), "similarity_search": options.get("similarity_search"), "auto_tagging": options.get("auto_tagging") and float(options.get("auto_tagging"))} params = dict( [ (k, __safe_value(v)) for (k,v) in params.items()] ) return params
def text(text, **options): params = {"timestamp": utils.now(), "text": text} for key in TEXT_PARAMS: params[key] = options.get(key) return call_api("text", params, **options)
def build_upload_params(**options): params = { "timestamp": utils.now(), "transformation": utils.generate_transformation_string(**options)[0], "public_id": options.get("public_id"), "callback": options.get("callback"), "format": options.get("format"), "type": options.get("type"), "backup": options.get("backup"), "faces": options.get("faces"), "image_metadata": options.get("image_metadata"), "exif": options.get("exif"), "colors": options.get("colors"), "headers": build_custom_headers(options.get("headers")), "eager": build_eager(options.get("eager")), "use_filename": options.get("use_filename"), "unique_filename": options.get("unique_filename"), "discard_original_filename": options.get("discard_original_filename"), "invalidate": options.get("invalidate"), "notification_url": options.get("notification_url"), "eager_notification_url": options.get("eager_notification_url"), "eager_async": options.get("eager_async"), "proxy": options.get("proxy"), "folder": options.get("folder"), "overwrite": options.get("overwrite"), "tags": options.get("tags") and ",".join(utils.build_array(options["tags"])), "allowed_formats": options.get("allowed_formats") and ",".join(utils.build_array(options["allowed_formats"])), "face_coordinates": utils.encode_double_array(options.get("face_coordinates")), "context": utils.encode_dict(options.get("context")), "moderation": options.get("moderation"), "raw_convert": options.get("raw_convert"), "ocr": options.get("ocr"), "categorization": options.get("categorization"), "detection": options.get("detection"), "similarity_search": options.get("similarity_search"), "auto_tagging": options.get("auto_tagging") and float(options.get("auto_tagging")) } params = dict([(k, __safe_value(v)) for (k, v) in params.items()]) return params
import cloudinary from cloudinary import uploader, utils, api from cloudinary.compat import PY3, urllib2 import unittest import tempfile import os import zipfile ARCHIVE_TAG = "archive_tag_" + utils.now() class ArchiveTest(unittest.TestCase): @classmethod def setUpClass(cls): cloudinary.reset_config() uploader.upload("tests/logo.png", tags = [ARCHIVE_TAG]) uploader.upload("tests/logo.png", tags = [ARCHIVE_TAG], transformation=dict(width=10)) @classmethod def tearDownClass(cls): api.delete_resources_by_tag(ARCHIVE_TAG) @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") def test_create_archive(self): """should successfully generate an archive""" result = uploader.create_archive(tags = [ARCHIVE_TAG]) self.assertEqual(2, result.get("file_count")) result = uploader.create_zip(tags = [ARCHIVE_TAG], transformations = [{"width": 0.5},{"width": 2.0}]) self.assertEqual(4, result.get("file_count")) @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") def test_archive_url(self): result = utils.download_zip_url(tags = [ARCHIVE_TAG], transformations = [{"width": 0.5},{"width": 2.0}])
import cloudinary from cloudinary import uploader, utils, api from cloudinary.compat import PY3, urllib2 import unittest import tempfile import os import zipfile ARCHIVE_TAG = "archive_tag_" + utils.now() class ArchiveTest(unittest.TestCase): @classmethod def setUpClass(cls): cloudinary.reset_config() uploader.upload("tests/logo.png", tags=[ARCHIVE_TAG]) uploader.upload("tests/logo.png", tags=[ARCHIVE_TAG], transformation=dict(width=10)) @classmethod def tearDownClass(cls): api.delete_resources_by_tag(ARCHIVE_TAG) @unittest.skipUnless(cloudinary.config().api_secret, "requires api_key/api_secret") def test_create_archive(self): """should successfully generate an archive""" result = uploader.create_archive(tags=[ARCHIVE_TAG]) self.assertEqual(2, result.get("file_count")) result = uploader.create_zip(tags=[ARCHIVE_TAG],
def setUp(self): if StreamingProfilesTest.initialized: return StreamingProfilesTest.initialized = True cloudinary.reset_config() if not cloudinary.config().api_secret: return StreamingProfilesTest.test_id = "api_test_{0}".format(utils.now())