imagekitio 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ignore +2 -0
- data/CHANGELOG.md +116 -0
- data/README.md +534 -705
- data/SECURITY.md +27 -0
- data/lib/imagekitio/client.rb +122 -195
- data/lib/imagekitio/errors.rb +226 -2
- data/lib/imagekitio/file_part.rb +58 -0
- data/lib/imagekitio/helpers/crypto_utils.rb +25 -0
- data/lib/imagekitio/helpers/helper.rb +689 -0
- data/lib/imagekitio/helpers/transformation_utils.rb +164 -0
- data/lib/imagekitio/helpers/uuid_utils.rb +18 -0
- data/lib/imagekitio/internal/transport/base_client.rb +567 -0
- data/lib/imagekitio/internal/transport/pooled_net_requester.rb +217 -0
- data/lib/imagekitio/internal/type/array_of.rb +168 -0
- data/lib/imagekitio/internal/type/base_model.rb +530 -0
- data/lib/imagekitio/internal/type/base_page.rb +55 -0
- data/lib/imagekitio/internal/type/boolean.rb +77 -0
- data/lib/imagekitio/internal/type/converter.rb +327 -0
- data/lib/imagekitio/internal/type/enum.rb +156 -0
- data/lib/imagekitio/internal/type/file_input.rb +111 -0
- data/lib/imagekitio/internal/type/hash_of.rb +188 -0
- data/lib/imagekitio/internal/type/request_parameters.rb +42 -0
- data/lib/imagekitio/internal/type/union.rb +250 -0
- data/lib/imagekitio/internal/type/unknown.rb +81 -0
- data/lib/imagekitio/internal/util.rb +915 -0
- data/lib/imagekitio/internal.rb +20 -0
- data/lib/imagekitio/models/accounts/origin_create_params.rb +24 -0
- data/lib/imagekitio/models/accounts/origin_delete_params.rb +16 -0
- data/lib/imagekitio/models/accounts/origin_get_params.rb +16 -0
- data/lib/imagekitio/models/accounts/origin_list_params.rb +16 -0
- data/lib/imagekitio/models/accounts/origin_list_response.rb +11 -0
- data/lib/imagekitio/models/accounts/origin_request.rb +547 -0
- data/lib/imagekitio/models/accounts/origin_response.rb +568 -0
- data/lib/imagekitio/models/accounts/origin_update_params.rb +24 -0
- data/lib/imagekitio/models/accounts/url_endpoint_create_params.rb +16 -0
- data/lib/imagekitio/models/accounts/url_endpoint_delete_params.rb +16 -0
- data/lib/imagekitio/models/accounts/url_endpoint_get_params.rb +16 -0
- data/lib/imagekitio/models/accounts/url_endpoint_list_params.rb +16 -0
- data/lib/imagekitio/models/accounts/url_endpoint_list_response.rb +11 -0
- data/lib/imagekitio/models/accounts/url_endpoint_request.rb +110 -0
- data/lib/imagekitio/models/accounts/url_endpoint_response.rb +123 -0
- data/lib/imagekitio/models/accounts/url_endpoint_update_params.rb +16 -0
- data/lib/imagekitio/models/accounts/usage_get_params.rb +37 -0
- data/lib/imagekitio/models/accounts/usage_get_response.rb +51 -0
- data/lib/imagekitio/models/asset_list_params.rb +158 -0
- data/lib/imagekitio/models/asset_list_response.rb +24 -0
- data/lib/imagekitio/models/base_overlay.rb +21 -0
- data/lib/imagekitio/models/base_webhook_event.rb +24 -0
- data/lib/imagekitio/models/beta/v2/file_upload_params.rb +510 -0
- data/lib/imagekitio/models/beta/v2/file_upload_response.rb +618 -0
- data/lib/imagekitio/models/cache/invalidation_create_params.rb +27 -0
- data/lib/imagekitio/models/cache/invalidation_create_response.rb +23 -0
- data/lib/imagekitio/models/cache/invalidation_get_params.rb +16 -0
- data/lib/imagekitio/models/cache/invalidation_get_response.rb +35 -0
- data/lib/imagekitio/models/custom_metadata_field.rb +243 -0
- data/lib/imagekitio/models/custom_metadata_field_create_params.rb +238 -0
- data/lib/imagekitio/models/custom_metadata_field_delete_params.rb +14 -0
- data/lib/imagekitio/models/custom_metadata_field_delete_response.rb +10 -0
- data/lib/imagekitio/models/custom_metadata_field_list_params.rb +36 -0
- data/lib/imagekitio/models/custom_metadata_field_list_response.rb +9 -0
- data/lib/imagekitio/models/custom_metadata_field_update_params.rb +212 -0
- data/lib/imagekitio/models/extensions.rb +136 -0
- data/lib/imagekitio/models/file.rb +497 -0
- data/lib/imagekitio/models/file_copy_params.rb +43 -0
- data/lib/imagekitio/models/file_copy_response.rb +10 -0
- data/lib/imagekitio/models/file_delete_params.rb +14 -0
- data/lib/imagekitio/models/file_get_params.rb +14 -0
- data/lib/imagekitio/models/file_move_params.rb +33 -0
- data/lib/imagekitio/models/file_move_response.rb +10 -0
- data/lib/imagekitio/models/file_rename_params.rb +61 -0
- data/lib/imagekitio/models/file_rename_response.rb +21 -0
- data/lib/imagekitio/models/file_update_params.rb +22 -0
- data/lib/imagekitio/models/file_update_response.rb +104 -0
- data/lib/imagekitio/models/file_upload_params.rb +540 -0
- data/lib/imagekitio/models/file_upload_response.rb +611 -0
- data/lib/imagekitio/models/files/bulk_add_tags_params.rb +35 -0
- data/lib/imagekitio/models/files/bulk_add_tags_response.rb +24 -0
- data/lib/imagekitio/models/files/bulk_delete_params.rb +27 -0
- data/lib/imagekitio/models/files/bulk_delete_response.rb +24 -0
- data/lib/imagekitio/models/files/bulk_remove_ai_tags_params.rb +35 -0
- data/lib/imagekitio/models/files/bulk_remove_ai_tags_response.rb +24 -0
- data/lib/imagekitio/models/files/bulk_remove_tags_params.rb +35 -0
- data/lib/imagekitio/models/files/bulk_remove_tags_response.rb +24 -0
- data/lib/imagekitio/models/files/metadata_get_from_url_params.rb +28 -0
- data/lib/imagekitio/models/files/metadata_get_params.rb +16 -0
- data/lib/imagekitio/models/files/version_delete_params.rb +22 -0
- data/lib/imagekitio/models/files/version_delete_response.rb +12 -0
- data/lib/imagekitio/models/files/version_get_params.rb +22 -0
- data/lib/imagekitio/models/files/version_list_params.rb +16 -0
- data/lib/imagekitio/models/files/version_list_response.rb +10 -0
- data/lib/imagekitio/models/files/version_restore_params.rb +22 -0
- data/lib/imagekitio/models/folder.rb +76 -0
- data/lib/imagekitio/models/folder_copy_params.rb +44 -0
- data/lib/imagekitio/models/folder_copy_response.rb +23 -0
- data/lib/imagekitio/models/folder_create_params.rb +43 -0
- data/lib/imagekitio/models/folder_create_response.rb +10 -0
- data/lib/imagekitio/models/folder_delete_params.rb +25 -0
- data/lib/imagekitio/models/folder_delete_response.rb +10 -0
- data/lib/imagekitio/models/folder_move_params.rb +34 -0
- data/lib/imagekitio/models/folder_move_response.rb +23 -0
- data/lib/imagekitio/models/folder_rename_params.rb +59 -0
- data/lib/imagekitio/models/folder_rename_response.rb +23 -0
- data/lib/imagekitio/models/folders/job_get_params.rb +16 -0
- data/lib/imagekitio/models/folders/job_get_response.rb +74 -0
- data/lib/imagekitio/models/get_image_attributes_options.rb +68 -0
- data/lib/imagekitio/models/image_overlay.rb +66 -0
- data/lib/imagekitio/models/metadata.rb +483 -0
- data/lib/imagekitio/models/overlay.rb +28 -0
- data/lib/imagekitio/models/overlay_position.rb +101 -0
- data/lib/imagekitio/models/overlay_timing.rb +97 -0
- data/lib/imagekitio/models/responsive_image_attributes.rb +48 -0
- data/lib/imagekitio/models/solid_color_overlay.rb +42 -0
- data/lib/imagekitio/models/solid_color_overlay_transformation.rb +135 -0
- data/lib/imagekitio/models/src_options.rb +96 -0
- data/lib/imagekitio/models/streaming_resolution.rb +22 -0
- data/lib/imagekitio/models/subtitle_overlay.rb +64 -0
- data/lib/imagekitio/models/subtitle_overlay_transformation.rb +113 -0
- data/lib/imagekitio/models/text_overlay.rb +65 -0
- data/lib/imagekitio/models/text_overlay_transformation.rb +267 -0
- data/lib/imagekitio/models/transformation.rb +1100 -0
- data/lib/imagekitio/models/transformation_position.rb +19 -0
- data/lib/imagekitio/models/unsafe_unwrap_webhook_event.rb +36 -0
- data/lib/imagekitio/models/unwrap_webhook_event.rb +36 -0
- data/lib/imagekitio/models/update_file_request.rb +164 -0
- data/lib/imagekitio/models/upload_post_transform_error_event.rb +180 -0
- data/lib/imagekitio/models/upload_post_transform_success_event.rb +143 -0
- data/lib/imagekitio/models/upload_pre_transform_error_event.rb +108 -0
- data/lib/imagekitio/models/upload_pre_transform_success_event.rb +690 -0
- data/lib/imagekitio/models/video_overlay.rb +64 -0
- data/lib/imagekitio/models/video_transformation_accepted_event.rb +279 -0
- data/lib/imagekitio/models/video_transformation_error_event.rb +326 -0
- data/lib/imagekitio/models/video_transformation_ready_event.rb +379 -0
- data/lib/imagekitio/models/webhook_unsafe_unwrap_params.rb +14 -0
- data/lib/imagekitio/models/webhook_unwrap_params.rb +14 -0
- data/lib/imagekitio/models.rb +160 -0
- data/lib/imagekitio/request_options.rb +77 -0
- data/lib/imagekitio/resources/accounts/origins.rb +145 -0
- data/lib/imagekitio/resources/accounts/url_endpoints.rb +151 -0
- data/lib/imagekitio/resources/accounts/usage.rb +46 -0
- data/lib/imagekitio/resources/accounts.rb +26 -0
- data/lib/imagekitio/resources/assets.rb +54 -0
- data/lib/imagekitio/resources/beta/v2/files.rb +110 -0
- data/lib/imagekitio/resources/beta/v2.rb +20 -0
- data/lib/imagekitio/resources/beta.rb +18 -0
- data/lib/imagekitio/resources/cache/invalidation.rb +66 -0
- data/lib/imagekitio/resources/cache.rb +18 -0
- data/lib/imagekitio/resources/custom_metadata_fields.rb +133 -0
- data/lib/imagekitio/resources/files/bulk.rb +131 -0
- data/lib/imagekitio/resources/files/metadata.rb +69 -0
- data/lib/imagekitio/resources/files/versions.rb +132 -0
- data/lib/imagekitio/resources/files.rb +305 -0
- data/lib/imagekitio/resources/folders/job.rb +39 -0
- data/lib/imagekitio/resources/folders.rb +166 -0
- data/lib/imagekitio/resources/webhooks.rb +30 -0
- data/lib/imagekitio/version.rb +5 -0
- data/lib/imagekitio.rb +181 -13
- data/manifest.yaml +15 -0
- data/rbi/imagekitio/client.rbi +92 -0
- data/rbi/imagekitio/errors.rbi +205 -0
- data/rbi/imagekitio/file_part.rbi +37 -0
- data/rbi/imagekitio/helpers/helper.rbi +41 -0
- data/rbi/imagekitio/internal/transport/base_client.rbi +295 -0
- data/rbi/imagekitio/internal/transport/pooled_net_requester.rbi +80 -0
- data/rbi/imagekitio/internal/type/array_of.rbi +104 -0
- data/rbi/imagekitio/internal/type/base_model.rbi +304 -0
- data/rbi/imagekitio/internal/type/base_page.rbi +42 -0
- data/rbi/imagekitio/internal/type/boolean.rbi +58 -0
- data/rbi/imagekitio/internal/type/converter.rbi +216 -0
- data/rbi/imagekitio/internal/type/enum.rbi +82 -0
- data/rbi/imagekitio/internal/type/file_input.rbi +59 -0
- data/rbi/imagekitio/internal/type/hash_of.rbi +104 -0
- data/rbi/imagekitio/internal/type/request_parameters.rbi +29 -0
- data/rbi/imagekitio/internal/type/union.rbi +128 -0
- data/rbi/imagekitio/internal/type/unknown.rbi +58 -0
- data/rbi/imagekitio/internal/util.rbi +487 -0
- data/rbi/imagekitio/internal.rbi +18 -0
- data/rbi/imagekitio/models/accounts/origin_create_params.rbi +81 -0
- data/rbi/imagekitio/models/accounts/origin_delete_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/origin_get_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/origin_list_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/origin_list_response.rbi +15 -0
- data/rbi/imagekitio/models/accounts/origin_request.rbi +775 -0
- data/rbi/imagekitio/models/accounts/origin_response.rbi +718 -0
- data/rbi/imagekitio/models/accounts/origin_update_params.rbi +81 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_create_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_delete_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_get_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_list_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_list_response.rbi +15 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_request.rbi +218 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_response.rbi +213 -0
- data/rbi/imagekitio/models/accounts/url_endpoint_update_params.rbi +34 -0
- data/rbi/imagekitio/models/accounts/usage_get_params.rbi +60 -0
- data/rbi/imagekitio/models/accounts/usage_get_response.rbi +89 -0
- data/rbi/imagekitio/models/asset_list_params.rbi +281 -0
- data/rbi/imagekitio/models/asset_list_response.rbi +28 -0
- data/rbi/imagekitio/models/base_overlay.rbi +44 -0
- data/rbi/imagekitio/models/base_webhook_event.rbi +33 -0
- data/rbi/imagekitio/models/beta/v2/file_upload_params.rbi +861 -0
- data/rbi/imagekitio/models/beta/v2/file_upload_response.rbi +1197 -0
- data/rbi/imagekitio/models/cache/invalidation_create_params.rbi +45 -0
- data/rbi/imagekitio/models/cache/invalidation_create_response.rbi +37 -0
- data/rbi/imagekitio/models/cache/invalidation_get_params.rbi +34 -0
- data/rbi/imagekitio/models/cache/invalidation_get_response.rbi +93 -0
- data/rbi/imagekitio/models/custom_metadata_field.rbi +422 -0
- data/rbi/imagekitio/models/custom_metadata_field_create_params.rbi +443 -0
- data/rbi/imagekitio/models/custom_metadata_field_delete_params.rbi +30 -0
- data/rbi/imagekitio/models/custom_metadata_field_delete_response.rbi +23 -0
- data/rbi/imagekitio/models/custom_metadata_field_list_params.rbi +66 -0
- data/rbi/imagekitio/models/custom_metadata_field_list_response.rbi +11 -0
- data/rbi/imagekitio/models/custom_metadata_field_update_params.rbi +376 -0
- data/rbi/imagekitio/models/extensions.rbi +274 -0
- data/rbi/imagekitio/models/file.rbi +789 -0
- data/rbi/imagekitio/models/file_copy_params.rbi +66 -0
- data/rbi/imagekitio/models/file_copy_response.rbi +23 -0
- data/rbi/imagekitio/models/file_delete_params.rbi +27 -0
- data/rbi/imagekitio/models/file_get_params.rbi +27 -0
- data/rbi/imagekitio/models/file_move_params.rbi +51 -0
- data/rbi/imagekitio/models/file_move_response.rbi +23 -0
- data/rbi/imagekitio/models/file_rename_params.rbi +102 -0
- data/rbi/imagekitio/models/file_rename_response.rbi +35 -0
- data/rbi/imagekitio/models/file_update_params.rbi +58 -0
- data/rbi/imagekitio/models/file_update_response.rbi +322 -0
- data/rbi/imagekitio/models/file_upload_params.rbi +897 -0
- data/rbi/imagekitio/models/file_upload_response.rbi +1176 -0
- data/rbi/imagekitio/models/files/bulk_add_tags_params.rbi +56 -0
- data/rbi/imagekitio/models/files/bulk_add_tags_response.rbi +41 -0
- data/rbi/imagekitio/models/files/bulk_delete_params.rbi +48 -0
- data/rbi/imagekitio/models/files/bulk_delete_response.rbi +41 -0
- data/rbi/imagekitio/models/files/bulk_remove_ai_tags_params.rbi +56 -0
- data/rbi/imagekitio/models/files/bulk_remove_ai_tags_response.rbi +41 -0
- data/rbi/imagekitio/models/files/bulk_remove_tags_params.rbi +56 -0
- data/rbi/imagekitio/models/files/bulk_remove_tags_response.rbi +41 -0
- data/rbi/imagekitio/models/files/metadata_get_from_url_params.rbi +47 -0
- data/rbi/imagekitio/models/files/metadata_get_params.rbi +34 -0
- data/rbi/imagekitio/models/files/version_delete_params.rbi +40 -0
- data/rbi/imagekitio/models/files/version_delete_response.rbi +25 -0
- data/rbi/imagekitio/models/files/version_get_params.rbi +40 -0
- data/rbi/imagekitio/models/files/version_list_params.rbi +34 -0
- data/rbi/imagekitio/models/files/version_list_response.rbi +13 -0
- data/rbi/imagekitio/models/files/version_restore_params.rbi +40 -0
- data/rbi/imagekitio/models/folder.rbi +121 -0
- data/rbi/imagekitio/models/folder_copy_params.rbi +68 -0
- data/rbi/imagekitio/models/folder_copy_response.rbi +33 -0
- data/rbi/imagekitio/models/folder_create_params.rbi +71 -0
- data/rbi/imagekitio/models/folder_create_response.rbi +23 -0
- data/rbi/imagekitio/models/folder_delete_params.rbi +40 -0
- data/rbi/imagekitio/models/folder_delete_response.rbi +23 -0
- data/rbi/imagekitio/models/folder_move_params.rbi +53 -0
- data/rbi/imagekitio/models/folder_move_response.rbi +33 -0
- data/rbi/imagekitio/models/folder_rename_params.rbi +98 -0
- data/rbi/imagekitio/models/folder_rename_response.rbi +33 -0
- data/rbi/imagekitio/models/folders/job_get_params.rbi +34 -0
- data/rbi/imagekitio/models/folders/job_get_response.rbi +173 -0
- data/rbi/imagekitio/models/get_image_attributes_options.rbi +121 -0
- data/rbi/imagekitio/models/image_overlay.rbi +109 -0
- data/rbi/imagekitio/models/metadata.rbi +813 -0
- data/rbi/imagekitio/models/overlay.rbi +28 -0
- data/rbi/imagekitio/models/overlay_position.rbi +148 -0
- data/rbi/imagekitio/models/overlay_timing.rbi +135 -0
- data/rbi/imagekitio/models/responsive_image_attributes.rbi +74 -0
- data/rbi/imagekitio/models/solid_color_overlay.rbi +79 -0
- data/rbi/imagekitio/models/solid_color_overlay_transformation.rbi +218 -0
- data/rbi/imagekitio/models/src_options.rbi +159 -0
- data/rbi/imagekitio/models/streaming_resolution.rbi +38 -0
- data/rbi/imagekitio/models/subtitle_overlay.rbi +114 -0
- data/rbi/imagekitio/models/subtitle_overlay_transformation.rbi +215 -0
- data/rbi/imagekitio/models/text_overlay.rbi +110 -0
- data/rbi/imagekitio/models/text_overlay_transformation.rbi +451 -0
- data/rbi/imagekitio/models/transformation.rbi +1646 -0
- data/rbi/imagekitio/models/transformation_position.rbi +28 -0
- data/rbi/imagekitio/models/unsafe_unwrap_webhook_event.rbi +33 -0
- data/rbi/imagekitio/models/unwrap_webhook_event.rbi +31 -0
- data/rbi/imagekitio/models/update_file_request.rbi +316 -0
- data/rbi/imagekitio/models/upload_post_transform_error_event.rbi +434 -0
- data/rbi/imagekitio/models/upload_post_transform_success_event.rbi +327 -0
- data/rbi/imagekitio/models/upload_pre_transform_error_event.rbi +244 -0
- data/rbi/imagekitio/models/upload_pre_transform_success_event.rbi +1300 -0
- data/rbi/imagekitio/models/video_overlay.rbi +105 -0
- data/rbi/imagekitio/models/video_transformation_accepted_event.rbi +659 -0
- data/rbi/imagekitio/models/video_transformation_error_event.rbi +772 -0
- data/rbi/imagekitio/models/video_transformation_ready_event.rbi +864 -0
- data/rbi/imagekitio/models/webhook_unsafe_unwrap_params.rbi +30 -0
- data/rbi/imagekitio/models/webhook_unwrap_params.rbi +27 -0
- data/rbi/imagekitio/models.rbi +135 -0
- data/rbi/imagekitio/request_options.rbi +59 -0
- data/rbi/imagekitio/resources/accounts/origins.rbi +91 -0
- data/rbi/imagekitio/resources/accounts/url_endpoints.rbi +129 -0
- data/rbi/imagekitio/resources/accounts/usage.rbi +36 -0
- data/rbi/imagekitio/resources/accounts.rbi +21 -0
- data/rbi/imagekitio/resources/assets.rbi +74 -0
- data/rbi/imagekitio/resources/beta/v2/files.rbi +193 -0
- data/rbi/imagekitio/resources/beta/v2.rbi +17 -0
- data/rbi/imagekitio/resources/beta.rbi +15 -0
- data/rbi/imagekitio/resources/cache/invalidation.rbi +44 -0
- data/rbi/imagekitio/resources/cache.rbi +15 -0
- data/rbi/imagekitio/resources/custom_metadata_fields.rbi +106 -0
- data/rbi/imagekitio/resources/files/bulk.rbi +88 -0
- data/rbi/imagekitio/resources/files/metadata.rbi +49 -0
- data/rbi/imagekitio/resources/files/versions.rbi +89 -0
- data/rbi/imagekitio/resources/files.rbi +364 -0
- data/rbi/imagekitio/resources/folders/job.rbi +29 -0
- data/rbi/imagekitio/resources/folders.rbi +146 -0
- data/rbi/imagekitio/resources/webhooks.rbi +50 -0
- data/rbi/imagekitio/version.rbi +5 -0
- data/sig/imagekitio/client.rbs +47 -0
- data/sig/imagekitio/errors.rbs +117 -0
- data/sig/imagekitio/file_part.rbs +21 -0
- data/sig/imagekitio/helpers/helper.rbs +24 -0
- data/sig/imagekitio/internal/transport/base_client.rbs +131 -0
- data/sig/imagekitio/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/imagekitio/internal/type/array_of.rbs +48 -0
- data/sig/imagekitio/internal/type/base_model.rbs +102 -0
- data/sig/imagekitio/internal/type/base_page.rbs +24 -0
- data/sig/imagekitio/internal/type/boolean.rbs +26 -0
- data/sig/imagekitio/internal/type/converter.rbs +79 -0
- data/sig/imagekitio/internal/type/enum.rbs +32 -0
- data/sig/imagekitio/internal/type/file_input.rbs +25 -0
- data/sig/imagekitio/internal/type/hash_of.rbs +48 -0
- data/sig/imagekitio/internal/type/request_parameters.rbs +19 -0
- data/sig/imagekitio/internal/type/union.rbs +52 -0
- data/sig/imagekitio/internal/type/unknown.rbs +26 -0
- data/sig/imagekitio/internal/util.rbs +185 -0
- data/sig/imagekitio/internal.rbs +9 -0
- data/sig/imagekitio/models/accounts/origin_create_params.rbs +30 -0
- data/sig/imagekitio/models/accounts/origin_delete_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/origin_get_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/origin_list_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/origin_list_response.rbs +10 -0
- data/sig/imagekitio/models/accounts/origin_request.rbs +468 -0
- data/sig/imagekitio/models/accounts/origin_response.rbs +418 -0
- data/sig/imagekitio/models/accounts/origin_update_params.rbs +30 -0
- data/sig/imagekitio/models/accounts/url_endpoint_create_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/url_endpoint_delete_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/url_endpoint_get_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/url_endpoint_list_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/url_endpoint_list_response.rbs +10 -0
- data/sig/imagekitio/models/accounts/url_endpoint_request.rbs +97 -0
- data/sig/imagekitio/models/accounts/url_endpoint_response.rbs +96 -0
- data/sig/imagekitio/models/accounts/url_endpoint_update_params.rbs +17 -0
- data/sig/imagekitio/models/accounts/usage_get_params.rbs +30 -0
- data/sig/imagekitio/models/accounts/usage_get_response.rbs +52 -0
- data/sig/imagekitio/models/asset_list_params.rbs +138 -0
- data/sig/imagekitio/models/asset_list_response.rbs +16 -0
- data/sig/imagekitio/models/base_overlay.rbs +31 -0
- data/sig/imagekitio/models/base_webhook_event.rbs +15 -0
- data/sig/imagekitio/models/beta/v2/file_upload_params.rbs +310 -0
- data/sig/imagekitio/models/beta/v2/file_upload_response.rbs +487 -0
- data/sig/imagekitio/models/cache/invalidation_create_params.rbs +25 -0
- data/sig/imagekitio/models/cache/invalidation_create_response.rbs +17 -0
- data/sig/imagekitio/models/cache/invalidation_get_params.rbs +17 -0
- data/sig/imagekitio/models/cache/invalidation_get_response.rbs +35 -0
- data/sig/imagekitio/models/custom_metadata_field.rbs +178 -0
- data/sig/imagekitio/models/custom_metadata_field_create_params.rbs +179 -0
- data/sig/imagekitio/models/custom_metadata_field_delete_params.rbs +15 -0
- data/sig/imagekitio/models/custom_metadata_field_delete_response.rbs +11 -0
- data/sig/imagekitio/models/custom_metadata_field_list_params.rbs +32 -0
- data/sig/imagekitio/models/custom_metadata_field_list_response.rbs +8 -0
- data/sig/imagekitio/models/custom_metadata_field_update_params.rbs +152 -0
- data/sig/imagekitio/models/extensions.rbs +132 -0
- data/sig/imagekitio/models/file.rbs +384 -0
- data/sig/imagekitio/models/file_copy_params.rbs +38 -0
- data/sig/imagekitio/models/file_copy_response.rbs +11 -0
- data/sig/imagekitio/models/file_delete_params.rbs +15 -0
- data/sig/imagekitio/models/file_get_params.rbs +14 -0
- data/sig/imagekitio/models/file_move_params.rbs +28 -0
- data/sig/imagekitio/models/file_move_response.rbs +11 -0
- data/sig/imagekitio/models/file_rename_params.rbs +34 -0
- data/sig/imagekitio/models/file_rename_response.rbs +15 -0
- data/sig/imagekitio/models/file_update_params.rbs +28 -0
- data/sig/imagekitio/models/file_update_response.rbs +120 -0
- data/sig/imagekitio/models/file_upload_params.rbs +327 -0
- data/sig/imagekitio/models/file_upload_response.rbs +483 -0
- data/sig/imagekitio/models/files/bulk_add_tags_params.rbs +30 -0
- data/sig/imagekitio/models/files/bulk_add_tags_response.rbs +20 -0
- data/sig/imagekitio/models/files/bulk_delete_params.rbs +26 -0
- data/sig/imagekitio/models/files/bulk_delete_response.rbs +20 -0
- data/sig/imagekitio/models/files/bulk_remove_ai_tags_params.rbs +30 -0
- data/sig/imagekitio/models/files/bulk_remove_ai_tags_response.rbs +20 -0
- data/sig/imagekitio/models/files/bulk_remove_tags_params.rbs +30 -0
- data/sig/imagekitio/models/files/bulk_remove_tags_response.rbs +20 -0
- data/sig/imagekitio/models/files/metadata_get_from_url_params.rbs +25 -0
- data/sig/imagekitio/models/files/metadata_get_params.rbs +17 -0
- data/sig/imagekitio/models/files/version_delete_params.rbs +25 -0
- data/sig/imagekitio/models/files/version_delete_response.rbs +13 -0
- data/sig/imagekitio/models/files/version_get_params.rbs +25 -0
- data/sig/imagekitio/models/files/version_list_params.rbs +17 -0
- data/sig/imagekitio/models/files/version_list_response.rbs +9 -0
- data/sig/imagekitio/models/files/version_restore_params.rbs +25 -0
- data/sig/imagekitio/models/folder.rbs +69 -0
- data/sig/imagekitio/models/folder_copy_params.rbs +38 -0
- data/sig/imagekitio/models/folder_copy_response.rbs +13 -0
- data/sig/imagekitio/models/folder_create_params.rbs +28 -0
- data/sig/imagekitio/models/folder_create_response.rbs +11 -0
- data/sig/imagekitio/models/folder_delete_params.rbs +23 -0
- data/sig/imagekitio/models/folder_delete_response.rbs +11 -0
- data/sig/imagekitio/models/folder_move_params.rbs +28 -0
- data/sig/imagekitio/models/folder_move_response.rbs +13 -0
- data/sig/imagekitio/models/folder_rename_params.rbs +34 -0
- data/sig/imagekitio/models/folder_rename_response.rbs +13 -0
- data/sig/imagekitio/models/folders/job_get_params.rbs +17 -0
- data/sig/imagekitio/models/folders/job_get_response.rbs +72 -0
- data/sig/imagekitio/models/get_image_attributes_options.rbs +43 -0
- data/sig/imagekitio/models/image_overlay.rbs +59 -0
- data/sig/imagekitio/models/metadata.rbs +546 -0
- data/sig/imagekitio/models/overlay.rbs +16 -0
- data/sig/imagekitio/models/overlay_position.rbs +85 -0
- data/sig/imagekitio/models/overlay_timing.rbs +66 -0
- data/sig/imagekitio/models/responsive_image_attributes.rbs +36 -0
- data/sig/imagekitio/models/solid_color_overlay.rbs +38 -0
- data/sig/imagekitio/models/solid_color_overlay_transformation.rbs +97 -0
- data/sig/imagekitio/models/src_options.rbs +64 -0
- data/sig/imagekitio/models/streaming_resolution.rbs +20 -0
- data/sig/imagekitio/models/subtitle_overlay.rbs +59 -0
- data/sig/imagekitio/models/subtitle_overlay_transformation.rbs +78 -0
- data/sig/imagekitio/models/text_overlay.rbs +59 -0
- data/sig/imagekitio/models/text_overlay_transformation.rbs +195 -0
- data/sig/imagekitio/models/transformation.rbs +763 -0
- data/sig/imagekitio/models/transformation_position.rbs +14 -0
- data/sig/imagekitio/models/unsafe_unwrap_webhook_event.rbs +18 -0
- data/sig/imagekitio/models/unwrap_webhook_event.rbs +18 -0
- data/sig/imagekitio/models/update_file_request.rbs +122 -0
- data/sig/imagekitio/models/upload_post_transform_error_event.rbs +192 -0
- data/sig/imagekitio/models/upload_post_transform_success_event.rbs +142 -0
- data/sig/imagekitio/models/upload_pre_transform_error_event.rbs +115 -0
- data/sig/imagekitio/models/upload_pre_transform_success_event.rbs +541 -0
- data/sig/imagekitio/models/video_overlay.rbs +59 -0
- data/sig/imagekitio/models/video_transformation_accepted_event.rbs +261 -0
- data/sig/imagekitio/models/video_transformation_error_event.rbs +300 -0
- data/sig/imagekitio/models/video_transformation_ready_event.rbs +359 -0
- data/sig/imagekitio/models/webhook_unsafe_unwrap_params.rbs +15 -0
- data/sig/imagekitio/models/webhook_unwrap_params.rbs +15 -0
- data/sig/imagekitio/models.rbs +119 -0
- data/sig/imagekitio/request_options.rbs +36 -0
- data/sig/imagekitio/resources/accounts/origins.rbs +34 -0
- data/sig/imagekitio/resources/accounts/url_endpoints.rbs +40 -0
- data/sig/imagekitio/resources/accounts/usage.rbs +15 -0
- data/sig/imagekitio/resources/accounts.rbs +13 -0
- data/sig/imagekitio/resources/assets.rbs +18 -0
- data/sig/imagekitio/resources/beta/v2/files.rbs +35 -0
- data/sig/imagekitio/resources/beta/v2.rbs +11 -0
- data/sig/imagekitio/resources/beta.rbs +9 -0
- data/sig/imagekitio/resources/cache/invalidation.rbs +19 -0
- data/sig/imagekitio/resources/cache.rbs +9 -0
- data/sig/imagekitio/resources/custom_metadata_fields.rbs +32 -0
- data/sig/imagekitio/resources/files/bulk.rbs +32 -0
- data/sig/imagekitio/resources/files/metadata.rbs +19 -0
- data/sig/imagekitio/resources/files/versions.rbs +32 -0
- data/sig/imagekitio/resources/files.rbs +76 -0
- data/sig/imagekitio/resources/folders/job.rbs +14 -0
- data/sig/imagekitio/resources/folders.rbs +40 -0
- data/sig/imagekitio/resources/webhooks.rbs +27 -0
- data/sig/imagekitio/version.rbs +3 -0
- metadata +470 -136
- data/Rakefile +0 -27
- data/lib/active_storage/active_storage.rb +0 -7
- data/lib/active_storage/service/ik_file.rb +0 -115
- data/lib/active_storage/service/image_kit_io_service.rb +0 -188
- data/lib/carrierwave/carrierwave.rb +0 -83
- data/lib/carrierwave/storage/ik_file.rb +0 -51
- data/lib/carrierwave/storage/imagekit_store.rb +0 -68
- data/lib/carrierwave/support/uri_filename.rb +0 -12
- data/lib/imagekitio/api_service/bulk.rb +0 -58
- data/lib/imagekitio/api_service/custom_metadata_field.rb +0 -52
- data/lib/imagekitio/api_service/file.rb +0 -221
- data/lib/imagekitio/api_service/folder.rb +0 -49
- data/lib/imagekitio/base.rb +0 -12
- data/lib/imagekitio/configurable.rb +0 -43
- data/lib/imagekitio/constant.rb +0 -36
- data/lib/imagekitio/constants/default.rb +0 -22
- data/lib/imagekitio/constants/error.rb +0 -69
- data/lib/imagekitio/constants/file.rb +0 -11
- data/lib/imagekitio/constants/supported_transformation.rb +0 -39
- data/lib/imagekitio/constants/url.rb +0 -14
- data/lib/imagekitio/railtie.rb +0 -4
- data/lib/imagekitio/request.rb +0 -98
- data/lib/imagekitio/sdk/version.rb +0 -5
- data/lib/imagekitio/url.rb +0 -216
- data/lib/imagekitio/utils/calculation.rb +0 -45
- data/lib/imagekitio/utils/formatter.rb +0 -48
- data/lib/imagekitio/utils/option_validator.rb +0 -36
- data/lib/tasks/imagekitio/imagekitio_tasks.rake +0 -4
data/README.md
CHANGED
|
@@ -1,915 +1,744 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[
|
|
8
|
-
|
|
9
|
-
[
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
# ImageKit.io Ruby SDK
|
|
2
|
+
|
|
3
|
+
The ImageKit Ruby library provides convenient access to the ImageKit REST API from any Ruby 3.2.0+ application. The library supports building and transforming URLs, generating signed URLs for secure content delivery, and handling file uploads. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/imagekit-developer/imagekit-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
The official [ImageKit Ruby documentation](https://imagekit.io/docs/integration/ruby) provides complete integration guides and examples.
|
|
8
|
+
|
|
9
|
+
If you're using Ruby on Rails, the [ImageKit Rails gem](https://github.com/imagekit-developer/imagekit-rails) builds on top of this SDK to provide [Rails-specific integrations](https://imagekit.io/docs/integration/ruby/ruby-on-rails) including Active Storage and view helpers.
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
- [Documentation](#documentation)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Usage](#usage)
|
|
16
|
+
- [File uploads](#file-uploads)
|
|
17
|
+
- [URL Generation](#url-generation)
|
|
18
|
+
- [Basic URL generation](#basic-url-generation)
|
|
19
|
+
- [URL generation with transformations](#url-generation-with-transformations)
|
|
20
|
+
- [URL generation with image overlay](#url-generation-with-image-overlay)
|
|
21
|
+
- [URL generation with text overlay](#url-generation-with-text-overlay)
|
|
22
|
+
- [Signed URLs for secure delivery](#signed-urls-for-secure-delivery)
|
|
23
|
+
- [Chained transformations](#chained-transformations)
|
|
24
|
+
- [Using raw parameter for custom transformations](#using-raw-parameter-for-custom-transformations)
|
|
25
|
+
- [Helper Methods](#helper-methods)
|
|
26
|
+
- [Authentication parameters for client-side uploads](#authentication-parameters-for-client-side-uploads)
|
|
27
|
+
- [Responsive image attributes](#responsive-image-attributes)
|
|
28
|
+
- [Handling errors](#handling-errors)
|
|
29
|
+
- [Retries](#retries)
|
|
30
|
+
- [Timeouts](#timeouts)
|
|
31
|
+
- [Advanced concepts](#advanced-concepts)
|
|
32
|
+
- [BaseModel](#basemodel)
|
|
33
|
+
- [Making custom or undocumented requests](#making-custom-or-undocumented-requests)
|
|
34
|
+
- [Concurrency & connection pooling](#concurrency--connection-pooling)
|
|
35
|
+
- [Sorbet](#sorbet)
|
|
36
|
+
- [Enums](#enums)
|
|
37
|
+
- [Versioning](#versioning)
|
|
38
|
+
- [Requirements](#requirements)
|
|
39
|
+
- [Contributing](#contributing)
|
|
40
40
|
|
|
41
41
|
## Installation
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
gem 'imagekitio'
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
And then execute:
|
|
50
|
-
```
|
|
51
|
-
$ bundle install
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Or install it yourself:
|
|
55
|
-
```
|
|
56
|
-
$ gem install imagekitio
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Initialization
|
|
60
|
-
|
|
61
|
-
Create a new file `config/initializers/imagekitio.rb` then add the configuration.
|
|
62
|
-
```ruby
|
|
63
|
-
ImageKitIo.configure do |config|
|
|
64
|
-
if Rails.env.development?
|
|
65
|
-
config.public_key = 'your_public_api_key'
|
|
66
|
-
config.private_key = 'your_private_api_key'
|
|
67
|
-
config.url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
|
|
68
|
-
end
|
|
69
|
-
config.service = :carrierwave
|
|
70
|
-
#config.service = :active_storage
|
|
71
|
-
#config.constants.MISSING_PRIVATE_KEY = 'custom error message'
|
|
72
|
-
end
|
|
73
|
-
```
|
|
74
|
-
#### CarrierWave
|
|
75
|
-
You can create a CarrierWave uploader to attach pictures to your database objects as their attributes. Skip to [this section](https://github.com/imagekit-developer/imagekit-ruby#file-upload) to upload images without designating them as database attributes. Make sure to add service `:carrierwave` as shown in [initialization section](#initialization).
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
rails g uploader <Uploading_attribute_name>
|
|
79
|
-
# For example, if you want to create an uploader for Avatar attribute, then use
|
|
80
|
-
rails g uploader Avatar
|
|
81
|
-
# Generated uploader's path will be app/uploaders/avatar_uploader.rb
|
|
82
|
-
```
|
|
45
|
+
<!-- x-release-please-start-version -->
|
|
83
46
|
|
|
84
|
-
After that, you need to edit your generated uploader and make the following changes:
|
|
85
47
|
```ruby
|
|
86
|
-
|
|
87
|
-
include ImageKitIo::CarrierWave
|
|
88
|
-
|
|
89
|
-
# If you want to add uploading options, then create this method inside the uploader file as an example
|
|
90
|
-
|
|
91
|
-
def options
|
|
92
|
-
options={
|
|
93
|
-
response_fields: 'isPrivateFile, tags',
|
|
94
|
-
tags: %w[abc def],
|
|
95
|
-
use_unique_file_name: false,
|
|
96
|
-
folder: "your_directory/"
|
|
97
|
-
}
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# If you want to set upload dir, then you can use the following method, or you can also use the options method.
|
|
101
|
-
# This method should return a string
|
|
102
|
-
def store_dir
|
|
103
|
-
"your_directory/"
|
|
104
|
-
end
|
|
48
|
+
gem "imagekitio", "~> 4.0.0"
|
|
105
49
|
```
|
|
106
50
|
|
|
107
|
-
|
|
51
|
+
<!-- x-release-please-end -->
|
|
108
52
|
|
|
109
|
-
|
|
110
|
-
class Employee < ApplicationRecord
|
|
111
|
-
attr_accessor :avatar
|
|
112
|
-
mount_uploader :avatar, AvatarUploader
|
|
113
|
-
end
|
|
114
|
-
```
|
|
53
|
+
## Usage
|
|
115
54
|
|
|
116
|
-
Get image url:
|
|
117
55
|
```ruby
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# To get the original image url, use
|
|
121
|
-
@employee.avatar.url
|
|
56
|
+
require "imagekitio"
|
|
122
57
|
|
|
123
|
-
|
|
124
|
-
|
|
58
|
+
image_kit = Imagekitio::Client.new(
|
|
59
|
+
private_key: ENV["IMAGEKIT_PRIVATE_KEY"], # This is the default and can be omitted
|
|
60
|
+
)
|
|
125
61
|
|
|
62
|
+
response = image_kit.files.upload(
|
|
63
|
+
file: Pathname("/path/to/file"),
|
|
64
|
+
file_name: "file-name.jpg"
|
|
65
|
+
)
|
|
126
66
|
|
|
127
|
-
|
|
128
|
-
# options is a transformation options
|
|
129
|
-
@employee.avatar.url_with(options)
|
|
67
|
+
puts(response.file_id)
|
|
130
68
|
```
|
|
131
69
|
|
|
132
|
-
|
|
70
|
+
### File uploads
|
|
133
71
|
|
|
134
|
-
|
|
72
|
+
Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.2/o/pathname) instance, or an `IO` stream.
|
|
135
73
|
|
|
136
74
|
```ruby
|
|
137
|
-
|
|
138
|
-
has_one_attached :avatar
|
|
139
|
-
end
|
|
140
|
-
```
|
|
75
|
+
require "pathname"
|
|
141
76
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
# If @employee is an object of your model that has data.
|
|
77
|
+
# Use `Pathname` to stream from disk (memory efficient, supports retries):
|
|
78
|
+
response = image_kit.files.upload(file: Pathname("/path/to/file"))
|
|
145
79
|
|
|
146
|
-
#
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Now, let's configure active_storage as a service for the imagekitio.
|
|
80
|
+
# Or pass file contents directly
|
|
81
|
+
response = image_kit.files.upload(file: File.read("/path/to/file"))
|
|
151
82
|
|
|
152
|
-
|
|
83
|
+
# Or, to control the filename and/or content type:
|
|
84
|
+
file = Imagekitio::FilePart.new(File.read("/path/to/file"), filename: "/path/to/file", content_type: "…")
|
|
85
|
+
response = image_kit.files.upload(file: file)
|
|
153
86
|
|
|
154
|
-
|
|
155
|
-
config.service = :active_storage
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Then add the imagekitio service in the `storage.yml` file:
|
|
159
|
-
|
|
160
|
-
```ruby
|
|
161
|
-
imagekitio:
|
|
162
|
-
service: ImageKitIo
|
|
87
|
+
puts(response.file_id)
|
|
163
88
|
```
|
|
164
89
|
|
|
90
|
+
Note that you can also pass a raw `IO` descriptor, but this disables retries, as the library can't be sure if the descriptor is a file or pipe (which cannot be rewound).
|
|
165
91
|
|
|
166
|
-
##
|
|
92
|
+
## URL Generation
|
|
167
93
|
|
|
168
|
-
|
|
94
|
+
The ImageKit SDK provides a powerful `helper.build_url()` method for generating optimized image and video URLs with transformations. Here are examples ranging from simple URLs to complex transformations with overlays and signed URLs.
|
|
169
95
|
|
|
170
|
-
|
|
171
|
-
* `File Upload`
|
|
172
|
-
* `File Management`
|
|
96
|
+
### Basic URL generation
|
|
173
97
|
|
|
174
|
-
|
|
98
|
+
Generate a simple URL without any transformations:
|
|
175
99
|
|
|
176
|
-
|
|
100
|
+
```ruby
|
|
101
|
+
require "imagekitio"
|
|
177
102
|
|
|
178
|
-
|
|
103
|
+
image_kit = Imagekitio::Client.new(
|
|
104
|
+
private_key: ENV["IMAGEKIT_PRIVATE_KEY"]
|
|
105
|
+
)
|
|
179
106
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
|
|
185
|
-
transformation: [{height: "300", width: "400", raw: "ar-4-3,q-40"}]
|
|
107
|
+
# Basic URL without transformations
|
|
108
|
+
url = image_kit.helper.build_url({
|
|
109
|
+
src: "/default-image.jpg",
|
|
110
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id"
|
|
186
111
|
})
|
|
187
|
-
```
|
|
188
112
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400,ar-4-3,q-40/default-image.jpg
|
|
113
|
+
puts url
|
|
114
|
+
# Output: https://ik.imagekit.io/your_imagekit_id/default-image.jpg
|
|
192
115
|
```
|
|
193
116
|
|
|
194
|
-
|
|
195
|
-
This method allows you to add transformation parameters to an absolute URL. For example, if you have configured a custom CNAME and have absolute asset URLs in your database or CMS, you will often need this.
|
|
196
|
-
|
|
117
|
+
You can also use absolute URLs:
|
|
197
118
|
|
|
198
119
|
```ruby
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
120
|
+
url = image_kit.helper.build_url({
|
|
121
|
+
src: "https://ik.imagekit.io/your_imagekit_id/default-image.jpg",
|
|
122
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id"
|
|
202
123
|
})
|
|
203
124
|
```
|
|
204
125
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
The `.url()` method accepts the following parameters
|
|
126
|
+
### URL generation with transformations
|
|
213
127
|
|
|
214
|
-
|
|
215
|
-
| :---------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
216
|
-
| url_endpoint | Optional. The base URL to be appended before the path of the image. If not specified, the URL Endpoint specified at the time of SDK initialization is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
|
|
217
|
-
| path | Conditional. This is the path at which the image exists. For example, `/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
|
|
218
|
-
| src | Conditional. This is the complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
|
|
219
|
-
| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. |
|
|
220
|
-
| transformation_position | Optional. The default value is `path` that places the transformation string as a path parameter in the URL. It can also be specified as `query`, which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
|
|
221
|
-
| query_parameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful if you want to add some versioning parameters to your URLs. |
|
|
222
|
-
| signed | Optional. Boolean. Default is `false`. If set to `true`, the SDK generates a signed image URL adding the image signature to the image URL. This can only be used if you are creating the URL with the `url_endpoint` and `path` parameters and not with the `src` parameter. |
|
|
223
|
-
| expire_seconds | Optional. Integer. Meant to be used along with the `signed` parameter to specify the time in seconds from now when the URL should expire. If specified, the URL contains the expiry timestamp in the URL, and the image signature is modified accordingly. |
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
## Examples of generating URLs
|
|
227
|
-
**1. Chained Transformations as a query parameter**
|
|
128
|
+
Apply common transformations like resizing, cropping, and format conversion:
|
|
228
129
|
|
|
229
130
|
```ruby
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
131
|
+
# URL with basic transformations
|
|
132
|
+
url = image_kit.helper.build_url({
|
|
133
|
+
src: "/path/to/image.jpg",
|
|
134
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
135
|
+
transformation: [
|
|
136
|
+
{
|
|
137
|
+
width: 400,
|
|
138
|
+
height: 300,
|
|
139
|
+
crop: :maintain_ratio,
|
|
140
|
+
quality: 80,
|
|
141
|
+
format_: :webp
|
|
142
|
+
}
|
|
143
|
+
]
|
|
240
144
|
})
|
|
145
|
+
# Output: https://ik.imagekit.io/your_imagekit_id/path/to/image.jpg?tr=w-400,h-300,c-maintain_ratio,q-80,f-webp
|
|
241
146
|
```
|
|
242
|
-
Sample Result URL -
|
|
243
|
-
```
|
|
244
|
-
https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400%3Art-90
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
**2. Sharpening and contrast transforms and a progressive JPG image**
|
|
248
|
-
|
|
249
|
-
There are some transforms like [Sharpening](https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation)
|
|
250
|
-
that can be added to the URL with or without any other value. To use such transforms without specifying a value, specify
|
|
251
|
-
the value as "-" in the transformation object. Otherwise, specify the value that you want to be
|
|
252
|
-
added to this transformation.
|
|
253
147
|
|
|
148
|
+
More transformation examples:
|
|
254
149
|
|
|
255
150
|
```ruby
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
151
|
+
# Image resizing and cropping
|
|
152
|
+
url = image_kit.helper.build_url({
|
|
153
|
+
src: "/product.jpg",
|
|
154
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
155
|
+
transformation: [
|
|
156
|
+
{
|
|
157
|
+
width: 800,
|
|
158
|
+
height: 600,
|
|
159
|
+
crop: :at_max,
|
|
160
|
+
focus: "auto"
|
|
161
|
+
}
|
|
162
|
+
]
|
|
264
163
|
})
|
|
265
|
-
```
|
|
266
164
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
165
|
+
# Image effects
|
|
166
|
+
url = image_kit.helper.build_url({
|
|
167
|
+
src: "/photo.jpg",
|
|
168
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
169
|
+
transformation: [
|
|
170
|
+
{
|
|
171
|
+
blur: 10,
|
|
172
|
+
grayscale: true,
|
|
173
|
+
radius: 20
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
})
|
|
271
177
|
|
|
272
|
-
|
|
178
|
+
# Format and quality optimization
|
|
179
|
+
url = image_kit.helper.build_url({
|
|
180
|
+
src: "/image.jpg",
|
|
181
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
182
|
+
transformation: [
|
|
183
|
+
{
|
|
184
|
+
format_: :auto,
|
|
185
|
+
quality: 85,
|
|
186
|
+
progressive: true
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
})
|
|
190
|
+
```
|
|
273
191
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
192
|
+
### URL generation with image overlay
|
|
193
|
+
|
|
194
|
+
Add image overlays to your base image:
|
|
195
|
+
|
|
196
|
+
```ruby
|
|
197
|
+
# URL with image overlay
|
|
198
|
+
url = image_kit.helper.build_url({
|
|
199
|
+
src: "/path/to/base-image.jpg",
|
|
200
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
201
|
+
transformation: [
|
|
202
|
+
{
|
|
203
|
+
width: 500,
|
|
204
|
+
height: 400,
|
|
205
|
+
overlay: {
|
|
206
|
+
type: :image,
|
|
207
|
+
input: "/path/to/overlay-logo.png",
|
|
208
|
+
position: {
|
|
209
|
+
x: 10,
|
|
210
|
+
y_: 10
|
|
211
|
+
},
|
|
212
|
+
transformation: [
|
|
213
|
+
{
|
|
214
|
+
width: 100,
|
|
215
|
+
height: 50
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
})
|
|
222
|
+
# Output: URL with image overlay positioned at x:10, y:10
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### URL generation with text overlay
|
|
226
|
+
|
|
227
|
+
Add customized text overlays:
|
|
228
|
+
|
|
229
|
+
```ruby
|
|
230
|
+
# URL with text overlay
|
|
231
|
+
url = image_kit.helper.build_url({
|
|
232
|
+
src: "/path/to/base-image.jpg",
|
|
233
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
234
|
+
transformation: [
|
|
235
|
+
{
|
|
236
|
+
width: 600,
|
|
237
|
+
height: 400,
|
|
238
|
+
overlay: {
|
|
239
|
+
type: :text,
|
|
240
|
+
text: "Sample Text Overlay",
|
|
241
|
+
position: {
|
|
242
|
+
x: 50,
|
|
243
|
+
y_: 50,
|
|
244
|
+
focus: :center
|
|
245
|
+
},
|
|
246
|
+
transformation: [
|
|
247
|
+
{
|
|
248
|
+
font_size: 40,
|
|
249
|
+
font_family: "Arial",
|
|
250
|
+
font_color: "FFFFFF",
|
|
251
|
+
typography: "b" # bold
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
]
|
|
257
|
+
})
|
|
258
|
+
# Output: URL with bold white Arial text overlay at center position
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
You can combine multiple overlays for complex compositions:
|
|
262
|
+
|
|
263
|
+
```ruby
|
|
264
|
+
# URL with multiple overlays (text + image)
|
|
265
|
+
url = image_kit.helper.build_url({
|
|
266
|
+
src: "/path/to/base-image.jpg",
|
|
267
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
268
|
+
transformation: [
|
|
269
|
+
{
|
|
270
|
+
width: 800,
|
|
271
|
+
height: 600,
|
|
272
|
+
overlay: {
|
|
273
|
+
type: :text,
|
|
274
|
+
text: "Header Text",
|
|
275
|
+
position: { x: 20, y_: 20 },
|
|
276
|
+
transformation: [{ font_size: 30, font_color: "000000" }]
|
|
277
|
+
}
|
|
279
278
|
},
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
279
|
+
{
|
|
280
|
+
overlay: {
|
|
281
|
+
type: :image,
|
|
282
|
+
input: "/watermark.png",
|
|
283
|
+
position: { focus: :bottom_right },
|
|
284
|
+
transformation: [{ width: 100, opacity: 70 }]
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
]
|
|
286
288
|
})
|
|
289
|
+
# Output: URL with text overlay at top-left and semi-transparent watermark at bottom-right
|
|
287
290
|
```
|
|
288
|
-
**Sample Result URL**
|
|
289
|
-
```
|
|
290
|
-
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?v=123&ik-t=1567358667&ik-s=f2c7cdacbe7707b71a83d49cf1c6110e3d701054
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
**4. Adding overlays**
|
|
294
|
-
|
|
295
|
-
ImageKit.io enables you to apply overlays to [images](https://docs.imagekit.io/features/image-transformations/overlay-using-layers) and [videos](https://docs.imagekit.io/features/video-transformation/overlay) using the raw parameter with the concept of [layers](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#layers). The raw parameter facilitates incorporating transformations directly in the URL. A layer is a distinct type of transformation that allows you to define an asset to serve as an overlay, along with its positioning and additional transformations.
|
|
296
291
|
|
|
297
|
-
|
|
292
|
+
### Signed URLs for secure delivery
|
|
298
293
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
For example:
|
|
294
|
+
Generate signed URLs that expire after a specified time for secure content delivery:
|
|
302
295
|
|
|
303
296
|
```ruby
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
297
|
+
# Generate a signed URL that expires in 1 hour (3600 seconds)
|
|
298
|
+
url = image_kit.helper.build_url({
|
|
299
|
+
src: "/private/secure-image.jpg",
|
|
300
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
301
|
+
transformation: [
|
|
302
|
+
{
|
|
303
|
+
width: 400,
|
|
304
|
+
height: 300,
|
|
305
|
+
quality: 90
|
|
306
|
+
}
|
|
307
|
+
],
|
|
308
|
+
signed: true,
|
|
309
|
+
expires_in: 3600 # URL expires in 1 hour
|
|
312
310
|
})
|
|
311
|
+
# Output: URL with signature parameters (?ik-t=timestamp&ik-s=signature)
|
|
312
|
+
|
|
313
|
+
# Generate a signed URL that doesn't expire
|
|
314
|
+
url = image_kit.helper.build_url({
|
|
315
|
+
src: "/private/secure-image.jpg",
|
|
316
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
317
|
+
signed: true
|
|
318
|
+
# No expires_in means the URL won't expire
|
|
319
|
+
})
|
|
320
|
+
# Output: URL with signature parameter (?ik-s=signature)
|
|
313
321
|
```
|
|
314
|
-
**Sample Result URL**
|
|
315
|
-
```
|
|
316
|
-
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-text,i-Imagekit,fs-50,l-end/default-image.jpg
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
**Image as overlays**
|
|
320
322
|
|
|
321
|
-
|
|
323
|
+
### Chained transformations
|
|
322
324
|
|
|
323
|
-
|
|
325
|
+
Apply multiple transformation steps by passing multiple transformation objects. Each transformation is applied sequentially:
|
|
324
326
|
|
|
325
327
|
```ruby
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
328
|
+
# First resize, then apply effects
|
|
329
|
+
url = image_kit.helper.build_url({
|
|
330
|
+
src: "/default-image.jpg",
|
|
331
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
332
|
+
transformation: [
|
|
333
|
+
{
|
|
334
|
+
width: 400,
|
|
335
|
+
height: 300
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
rotation: 90,
|
|
339
|
+
blur: 5
|
|
340
|
+
}
|
|
341
|
+
]
|
|
334
342
|
})
|
|
335
|
-
|
|
336
|
-
**Sample Result URL**
|
|
337
|
-
```
|
|
338
|
-
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end/default-image.jpg
|
|
343
|
+
# Output: https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-400,h-300:rt-90,bl-5
|
|
339
344
|
```
|
|
340
345
|
|
|
341
|
-
|
|
346
|
+
### Using raw parameter for custom transformations
|
|
342
347
|
|
|
343
|
-
You can
|
|
344
|
-
|
|
345
|
-
For example:
|
|
348
|
+
ImageKit frequently adds new transformation parameters that might not yet be documented in the SDK. You can use the `raw` parameter to access these features or create custom transformation strings:
|
|
346
349
|
|
|
347
350
|
```ruby
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
351
|
+
# Using raw parameter for custom transformations
|
|
352
|
+
url = image_kit.helper.build_url({
|
|
353
|
+
src: "/path/to/image.jpg",
|
|
354
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
355
|
+
transformation: [
|
|
356
|
+
{
|
|
357
|
+
width: 400,
|
|
358
|
+
height: 300,
|
|
359
|
+
raw: "something-new"
|
|
360
|
+
}
|
|
361
|
+
]
|
|
356
362
|
})
|
|
363
|
+
# Output: https://ik.imagekit.io/your_imagekit_id/path/to/image.jpg?tr=w-400,h-300,something-new
|
|
357
364
|
```
|
|
358
|
-
**Sample Result URL**
|
|
359
|
-
```
|
|
360
|
-
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end/img/sample-video.mp4
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
**5. Arithmetic expressions in transformations**
|
|
364
|
-
|
|
365
|
-
ImageKit allows use of [arithmetic expressions](https://docs.imagekit.io/features/arithmetic-expressions-in-transformations) in certain dimension and position-related parameters, making media transformations more flexible and dynamic.
|
|
366
365
|
|
|
367
|
-
|
|
366
|
+
You can control where transformations appear in the URL:
|
|
368
367
|
|
|
369
368
|
```ruby
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-iw_div_4,h-ih_div_2,b-cw_mul_0.05_yellow
|
|
369
|
+
# Add transformations to the URL path instead of query parameters
|
|
370
|
+
url = image_kit.helper.build_url({
|
|
371
|
+
src: "/default-image.jpg",
|
|
372
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
373
|
+
transformation_position: :path,
|
|
374
|
+
transformation: [
|
|
375
|
+
{
|
|
376
|
+
width: 400,
|
|
377
|
+
height: 300
|
|
378
|
+
}
|
|
379
|
+
]
|
|
380
|
+
})
|
|
381
|
+
# Output: https://ik.imagekit.io/your_imagekit_id/tr:w-400,h-300/default-image.jpg
|
|
384
382
|
```
|
|
385
383
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations). The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler, and readable.
|
|
389
|
-
|
|
390
|
-
If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using the `url` function.
|
|
391
|
-
|
|
392
|
-
If you want to generate transformations in your application and add them to the URL as it is, use the `raw` parameter.
|
|
393
|
-
|
|
394
|
-
| Supported Transformation Name | Translates to parameter |
|
|
395
|
-
|-------------------------------|-------------------------|
|
|
396
|
-
| height | h |
|
|
397
|
-
| width | w |
|
|
398
|
-
| aspect_ratio | ar |
|
|
399
|
-
| quality | q |
|
|
400
|
-
| crop | c |
|
|
401
|
-
| crop_mode | cm |
|
|
402
|
-
| x | x |
|
|
403
|
-
| y | y |
|
|
404
|
-
| focus | fo |
|
|
405
|
-
| format | f |
|
|
406
|
-
| radius | r |
|
|
407
|
-
| background | bg |
|
|
408
|
-
| border | b |
|
|
409
|
-
| rotation | rt |
|
|
410
|
-
| blur | bl |
|
|
411
|
-
| named | n |
|
|
412
|
-
| progressive | pr |
|
|
413
|
-
| lossless | lo |
|
|
414
|
-
| trim | t |
|
|
415
|
-
| metadata | md |
|
|
416
|
-
| color_profile | cp |
|
|
417
|
-
| default_image | di |
|
|
418
|
-
| dpr | dpr |
|
|
419
|
-
| effect_sharpen | e-sharpen |
|
|
420
|
-
| effect_usm | e-usm |
|
|
421
|
-
| effect_contrast | e-contrast |
|
|
422
|
-
| effect_gray | e-grayscale |
|
|
423
|
-
| effect_shadow | e-shadow |
|
|
424
|
-
| effect_gradient | e-gradient |
|
|
425
|
-
| original | orig |
|
|
426
|
-
| raw | `replaced by the parameter value` |
|
|
427
|
-
|
|
428
|
-
## File Upload
|
|
429
|
-
This method can be used to directly upload images to your ImageKit Media Library without giving it the designation of an attribute of any database object.
|
|
430
|
-
|
|
431
|
-
The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media library. It
|
|
432
|
-
accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
|
|
433
|
-
|
|
434
|
-
The `upload()` method requires at least the `file` and the `file_name` parameter to upload a file and returns
|
|
435
|
-
a callback with the `error` and `result` as arguments. You can pass other parameters supported by the
|
|
436
|
-
ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to specify tags for a file at the time of upload, use the `tags` parameter as specified in the [documentation here](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
|
|
437
|
-
|
|
438
|
-
Simple usage
|
|
384
|
+
Add custom query parameters:
|
|
439
385
|
|
|
440
386
|
```ruby
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
post: [
|
|
450
|
-
{
|
|
451
|
-
type: 'transformation',
|
|
452
|
-
value: 'w-100'
|
|
453
|
-
}
|
|
454
|
-
]
|
|
455
|
-
},
|
|
456
|
-
checks: "'request.folder' : '/'" # To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
|
|
457
|
-
is_published: true
|
|
458
|
-
)
|
|
459
|
-
|
|
387
|
+
url = image_kit.helper.build_url({
|
|
388
|
+
src: "/default-image.jpg",
|
|
389
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
390
|
+
query_parameters: {
|
|
391
|
+
version: "1",
|
|
392
|
+
cache: "max"
|
|
393
|
+
}
|
|
394
|
+
})
|
|
460
395
|
```
|
|
461
396
|
|
|
462
|
-
|
|
463
|
-
servers. If the upload fails, `error` will be the same as what is received from ImageKit's servers, and the result will
|
|
464
|
-
be `None`.
|
|
465
|
-
|
|
466
|
-
## File Management
|
|
397
|
+
## Helper Methods
|
|
467
398
|
|
|
468
|
-
The SDK provides
|
|
469
|
-
to manage your files. This also returns `error` and `result`. The `error` will be `None` if API succeeds.
|
|
399
|
+
The SDK provides several helper methods for common ImageKit operations.
|
|
470
400
|
|
|
471
|
-
|
|
401
|
+
### Authentication parameters for client-side uploads
|
|
472
402
|
|
|
473
|
-
|
|
474
|
-
in the [documentation here](https://docs.imagekit.io/api-reference/media-api/list-and-search-files#list-and-search-file-api) can be passed with the
|
|
475
|
-
correct values to get the results.
|
|
403
|
+
Generate authentication parameters for secure client-side file uploads. These parameters allow you to securely upload files directly from the browser without exposing your private API key:
|
|
476
404
|
|
|
477
405
|
```ruby
|
|
478
|
-
imagekitio
|
|
479
|
-
skip: 0,
|
|
480
|
-
limit: 5
|
|
481
|
-
)
|
|
482
|
-
```
|
|
483
|
-
**Get File Details**
|
|
406
|
+
require "imagekitio"
|
|
484
407
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
```ruby
|
|
488
|
-
imagekitio.get_file_details(
|
|
489
|
-
file_id: '598821f949c0a938d57563bd'
|
|
408
|
+
image_kit = Imagekitio::Client.new(
|
|
409
|
+
private_key: ENV["IMAGEKIT_PRIVATE_KEY"]
|
|
490
410
|
)
|
|
491
|
-
```
|
|
492
411
|
|
|
493
|
-
|
|
412
|
+
# Generate authentication parameters with default expiry (30 minutes)
|
|
413
|
+
auth_params = image_kit.helper.get_authentication_parameters
|
|
494
414
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
imagekit.get_file_metadata(
|
|
498
|
-
file_id: '598821f949c0a938d57563bd'
|
|
499
|
-
)
|
|
415
|
+
puts auth_params
|
|
416
|
+
# Output: { token: "unique-token", expire: 1234567890, signature: "signature-hash" }
|
|
500
417
|
```
|
|
501
418
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
Accepts the remote file url and fetches the metadata as per the [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-from-remote-url)
|
|
419
|
+
Customize the token and expiration:
|
|
505
420
|
|
|
506
421
|
```ruby
|
|
507
|
-
|
|
508
|
-
|
|
422
|
+
# Custom token and expiry (1 hour from now)
|
|
423
|
+
auth_params = image_kit.helper.get_authentication_parameters(
|
|
424
|
+
token: "my-custom-token",
|
|
425
|
+
expire: Time.now.to_i + 3600
|
|
509
426
|
)
|
|
427
|
+
# Output: { token: "my-custom-token", expire: 1234567890, signature: "generated-signature" }
|
|
510
428
|
```
|
|
511
429
|
|
|
512
|
-
|
|
430
|
+
These authentication parameters can be used in client-side upload forms to securely upload files without exposing your private API key.
|
|
513
431
|
|
|
514
|
-
|
|
515
|
-
The first argument to the `update_field_details` method is the file ID, and a second argument is an object with the
|
|
516
|
-
parameters to be updated.
|
|
432
|
+
### Responsive image attributes
|
|
517
433
|
|
|
518
|
-
|
|
519
|
-
imagekitio.update_file_details(
|
|
520
|
-
file_id: '598821f949c0a938d57563bd',
|
|
521
|
-
tags: ["image_tag"],
|
|
522
|
-
custom_coordinates: "10,10,100, 100"
|
|
523
|
-
)
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
**Update publish status**
|
|
528
|
-
|
|
529
|
-
If `publish` is included in the update options, no other parameters are allowed. If any are present, an error will be returned: `Your request cannot contain any other parameters when publish is present`.
|
|
434
|
+
Generate responsive image attributes for HTML `<img>` tags. This creates optimized `srcset` and `sizes` attributes for responsive images:
|
|
530
435
|
|
|
531
436
|
```ruby
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
437
|
+
# Width-based responsive images (generates w descriptors)
|
|
438
|
+
attrs = image_kit.helper.get_responsive_image_attributes({
|
|
439
|
+
src: "/default-image.jpg",
|
|
440
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
441
|
+
sizes: "(min-width: 768px) 50vw, 100vw",
|
|
442
|
+
transformation: [
|
|
443
|
+
{
|
|
444
|
+
quality: 80,
|
|
445
|
+
format_: :auto
|
|
537
446
|
}
|
|
538
|
-
|
|
539
|
-
|
|
447
|
+
]
|
|
448
|
+
})
|
|
540
449
|
|
|
541
|
-
|
|
450
|
+
puts attrs.src
|
|
451
|
+
# Largest candidate URL
|
|
542
452
|
|
|
543
|
-
|
|
453
|
+
puts attrs.src_set
|
|
454
|
+
# URL1 640w, URL2 750w, URL3 1080w, ...
|
|
544
455
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
source_file_path: '/path/to/file.jpg',
|
|
548
|
-
destination_path: '/folder/to/copy/into',
|
|
549
|
-
include_file_versions: true #default false
|
|
550
|
-
)
|
|
456
|
+
puts attrs.sizes
|
|
457
|
+
# (min-width: 768px) 50vw, 100vw
|
|
551
458
|
```
|
|
552
459
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
Move file from one folder to another folder using the source file path and destination path as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-file)
|
|
460
|
+
DPR-based responsive images (generates x descriptors):
|
|
556
461
|
|
|
557
462
|
```ruby
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
463
|
+
# When width is provided without sizes, generates 1x and 2x variants
|
|
464
|
+
attrs = image_kit.helper.get_responsive_image_attributes({
|
|
465
|
+
src: "/profile.jpg",
|
|
466
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
467
|
+
width: 400,
|
|
468
|
+
transformation: [
|
|
469
|
+
{
|
|
470
|
+
quality: 85
|
|
471
|
+
}
|
|
472
|
+
]
|
|
473
|
+
})
|
|
565
474
|
|
|
566
|
-
|
|
475
|
+
puts attrs.src_set
|
|
476
|
+
# URL1 1x, URL2 2x
|
|
567
477
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
file_path: '/path/to/old-file-name.jpg',
|
|
571
|
-
new_file_name: 'new-file-name.jpg',
|
|
572
|
-
purge_cache: true #optional
|
|
573
|
-
)
|
|
478
|
+
puts attrs.width
|
|
479
|
+
# 400
|
|
574
480
|
```
|
|
575
481
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file). The method accepts the file ID of the file that has to be deleted.
|
|
482
|
+
Custom breakpoints for device widths:
|
|
579
483
|
|
|
580
484
|
```ruby
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
485
|
+
attrs = image_kit.helper.get_responsive_image_attributes({
|
|
486
|
+
src: "/default-image.jpg",
|
|
487
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
488
|
+
sizes: "100vw",
|
|
489
|
+
device_breakpoints: [320, 640, 1024, 1920],
|
|
490
|
+
image_breakpoints: [16, 32, 64],
|
|
491
|
+
transformation: [
|
|
492
|
+
{
|
|
493
|
+
crop: :at_max
|
|
494
|
+
}
|
|
495
|
+
]
|
|
496
|
+
})
|
|
584
497
|
```
|
|
585
|
-
**File versions**
|
|
586
498
|
|
|
587
|
-
|
|
499
|
+
The returned attributes can be directly used in your HTML:
|
|
588
500
|
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
501
|
+
```erb
|
|
502
|
+
<img
|
|
503
|
+
src="<%= attrs.src %>"
|
|
504
|
+
srcset="<%= attrs.src_set %>"
|
|
505
|
+
sizes="<%= attrs.sizes %>"
|
|
506
|
+
alt="Responsive image"
|
|
507
|
+
/>
|
|
593
508
|
```
|
|
594
|
-
**File version details**
|
|
595
509
|
|
|
596
|
-
|
|
510
|
+
Generate signed responsive image URLs:
|
|
597
511
|
|
|
598
512
|
```ruby
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
513
|
+
# Generate signed responsive image URLs
|
|
514
|
+
attrs = image_kit.helper.get_responsive_image_attributes({
|
|
515
|
+
src: "/default-image.jpg",
|
|
516
|
+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
|
|
517
|
+
sizes: "100vw",
|
|
518
|
+
signed: true,
|
|
519
|
+
expires_in: 3600,
|
|
520
|
+
transformation: [
|
|
521
|
+
{
|
|
522
|
+
quality: 80
|
|
523
|
+
}
|
|
524
|
+
]
|
|
525
|
+
})
|
|
603
526
|
```
|
|
604
527
|
|
|
605
|
-
|
|
528
|
+
### Handling errors
|
|
606
529
|
|
|
607
|
-
|
|
530
|
+
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Imagekitio::Errors::APIError` will be thrown:
|
|
608
531
|
|
|
609
532
|
```ruby
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
533
|
+
begin
|
|
534
|
+
file = image_kit.files.upload(
|
|
535
|
+
file: File.read("/path/to/file.jpg"),
|
|
536
|
+
file_name: "file-name.jpg"
|
|
537
|
+
)
|
|
538
|
+
rescue Imagekitio::Errors::APIConnectionError => e
|
|
539
|
+
puts("The server could not be reached")
|
|
540
|
+
puts(e.cause) # an underlying Exception, likely raised within `net/http`
|
|
541
|
+
rescue Imagekitio::Errors::RateLimitError => e
|
|
542
|
+
puts("A 429 status code was received; we should back off a bit.")
|
|
543
|
+
rescue Imagekitio::Errors::APIStatusError => e
|
|
544
|
+
puts("Another non-200-range status code was received")
|
|
545
|
+
puts(e.status)
|
|
546
|
+
end
|
|
614
547
|
```
|
|
615
548
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
Restore deleted file version as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/restore-file-version). The method accepts the file ID and version ID of the file.
|
|
549
|
+
Error codes are as follows:
|
|
619
550
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
551
|
+
| Cause | Error Type |
|
|
552
|
+
| ---------------- | -------------------------- |
|
|
553
|
+
| HTTP 400 | `BadRequestError` |
|
|
554
|
+
| HTTP 401 | `AuthenticationError` |
|
|
555
|
+
| HTTP 403 | `PermissionDeniedError` |
|
|
556
|
+
| HTTP 404 | `NotFoundError` |
|
|
557
|
+
| HTTP 409 | `ConflictError` |
|
|
558
|
+
| HTTP 422 | `UnprocessableEntityError` |
|
|
559
|
+
| HTTP 429 | `RateLimitError` |
|
|
560
|
+
| HTTP >= 500 | `InternalServerError` |
|
|
561
|
+
| Other HTTP error | `APIStatusError` |
|
|
562
|
+
| Timeout | `APITimeoutError` |
|
|
563
|
+
| Network error | `APIConnectionError` |
|
|
626
564
|
|
|
627
|
-
|
|
565
|
+
### Retries
|
|
628
566
|
|
|
629
|
-
|
|
630
|
-
deleted.
|
|
567
|
+
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
|
|
631
568
|
|
|
632
|
-
|
|
633
|
-
imagekitio.delete_bulk_files(
|
|
634
|
-
file_ids: ["598821f949c0a938d57563bd", "598821f949c0a938d57543bd"]
|
|
635
|
-
)
|
|
636
|
-
```
|
|
569
|
+
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
|
|
637
570
|
|
|
638
|
-
|
|
639
|
-
Programmatically issue a clear cache request as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache).
|
|
640
|
-
Accepts the full URL of the file for which the cache has to be cleared.
|
|
571
|
+
You can use the `max_retries` option to configure or disable this:
|
|
641
572
|
|
|
642
573
|
```ruby
|
|
643
|
-
|
|
644
|
-
|
|
574
|
+
# Configure the default for all requests:
|
|
575
|
+
image_kit = Imagekitio::Client.new(
|
|
576
|
+
max_retries: 0 # default is 2
|
|
645
577
|
)
|
|
646
|
-
```
|
|
647
|
-
**Purge Cache Status**
|
|
648
|
-
|
|
649
|
-
Get the purge cache request status using the request ID returned when a purge cache request gets submitted as per the
|
|
650
|
-
[API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache-status)
|
|
651
578
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
579
|
+
# Or, configure per-request:
|
|
580
|
+
image_kit.files.upload(
|
|
581
|
+
file: File.read("/path/to/file.jpg"),
|
|
582
|
+
file_name: "file-name.jpg",
|
|
583
|
+
request_options: {max_retries: 5}
|
|
655
584
|
)
|
|
656
585
|
```
|
|
657
586
|
|
|
658
|
-
|
|
587
|
+
### Timeouts
|
|
659
588
|
|
|
660
|
-
|
|
589
|
+
By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
|
|
661
590
|
|
|
662
591
|
```ruby
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
592
|
+
# Configure the default for all requests:
|
|
593
|
+
image_kit = Imagekitio::Client.new(
|
|
594
|
+
timeout: nil # default is 60
|
|
666
595
|
)
|
|
667
|
-
```
|
|
668
596
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
imagekitio.delete_bulk_tags(
|
|
675
|
-
file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
|
|
676
|
-
tags: ['custom_tags', 'image']
|
|
597
|
+
# Or, configure per-request:
|
|
598
|
+
image_kit.files.upload(
|
|
599
|
+
file: File.read("/path/to/file.jpg"),
|
|
600
|
+
file_name: "file-name.jpg",
|
|
601
|
+
request_options: {timeout: 5}
|
|
677
602
|
)
|
|
678
603
|
```
|
|
679
604
|
|
|
680
|
-
|
|
605
|
+
On timeout, `Imagekitio::Errors::APITimeoutError` is raised.
|
|
681
606
|
|
|
682
|
-
|
|
607
|
+
Note that requests that time out are retried by default.
|
|
683
608
|
|
|
684
|
-
|
|
685
|
-
imagekitio.delete_bulk_ai_tags(
|
|
686
|
-
file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
|
|
687
|
-
ai_tags: ['custom_ai_tags']
|
|
688
|
-
)
|
|
689
|
-
```
|
|
609
|
+
## Advanced concepts
|
|
690
610
|
|
|
691
|
-
|
|
611
|
+
### BaseModel
|
|
692
612
|
|
|
693
|
-
|
|
613
|
+
All parameter and response objects inherit from `Imagekitio::Internal::Type::BaseModel`, which provides several conveniences, including:
|
|
694
614
|
|
|
695
|
-
|
|
696
|
-
imagekitio.create_folder(
|
|
697
|
-
folder_name: 'new_folder',
|
|
698
|
-
parent_folder_path: 'source/folder/path' #optional
|
|
699
|
-
)
|
|
700
|
-
```
|
|
615
|
+
1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
|
|
701
616
|
|
|
617
|
+
2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
|
|
702
618
|
|
|
703
|
-
|
|
619
|
+
3. Both instances and the classes themselves can be pretty-printed.
|
|
704
620
|
|
|
705
|
-
|
|
621
|
+
4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
|
|
706
622
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
destination_path: '/folder/to/copy/into',
|
|
711
|
-
include_file_versions: true #default false
|
|
712
|
-
)
|
|
713
|
-
```
|
|
623
|
+
### Making custom or undocumented requests
|
|
624
|
+
|
|
625
|
+
#### Undocumented properties
|
|
714
626
|
|
|
715
|
-
|
|
627
|
+
You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
|
|
716
628
|
|
|
717
|
-
|
|
629
|
+
Note: the `extra_` parameters of the same name overrides the documented parameters.
|
|
718
630
|
|
|
719
631
|
```ruby
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
632
|
+
response =
|
|
633
|
+
image_kit.files.upload(
|
|
634
|
+
file: File.read("/path/to/file.jpg"),
|
|
635
|
+
file_name: "file-name.jpg",
|
|
636
|
+
request_options: {
|
|
637
|
+
extra_query: {my_query_parameter: value},
|
|
638
|
+
extra_body: {my_body_parameter: value},
|
|
639
|
+
extra_headers: {"my-header": value}
|
|
640
|
+
}
|
|
641
|
+
)
|
|
725
642
|
|
|
726
|
-
|
|
643
|
+
puts(response[:my_undocumented_property])
|
|
644
|
+
```
|
|
727
645
|
|
|
728
|
-
|
|
646
|
+
#### Undocumented request params
|
|
729
647
|
|
|
730
|
-
|
|
731
|
-
imagekitio.delete_folder(
|
|
732
|
-
folder_path: 'folder/to/delete'
|
|
733
|
-
)
|
|
734
|
-
```
|
|
648
|
+
If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
|
|
735
649
|
|
|
736
|
-
|
|
650
|
+
#### Undocumented endpoints
|
|
737
651
|
|
|
738
|
-
|
|
652
|
+
To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
|
|
739
653
|
|
|
740
654
|
```ruby
|
|
741
|
-
|
|
742
|
-
|
|
655
|
+
response = client.request(
|
|
656
|
+
method: :post,
|
|
657
|
+
path: '/undocumented/endpoint',
|
|
658
|
+
query: {"dog": "woof"},
|
|
659
|
+
headers: {"useful-header": "interesting-value"},
|
|
660
|
+
body: {"hello": "world"}
|
|
743
661
|
)
|
|
744
662
|
```
|
|
745
663
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
Create custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)
|
|
664
|
+
### Concurrency & connection pooling
|
|
749
665
|
|
|
750
|
-
|
|
666
|
+
The `Imagekitio::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
|
|
751
667
|
|
|
752
|
-
|
|
753
|
-
name: 'price',
|
|
754
|
-
label: 'price_label',
|
|
755
|
-
schema: {
|
|
756
|
-
'type': 'Number',
|
|
757
|
-
'minValue': 100,
|
|
758
|
-
'maxValue': 300
|
|
759
|
-
}
|
|
760
|
-
)
|
|
761
|
-
```
|
|
668
|
+
Each instance of `Imagekitio::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
|
|
762
669
|
|
|
763
|
-
|
|
670
|
+
When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
|
|
764
671
|
|
|
765
|
-
|
|
672
|
+
Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
|
|
766
673
|
|
|
767
|
-
|
|
768
|
-
imagekitio.get_custom_metadata_fields(
|
|
769
|
-
include_deleted: true #optional
|
|
770
|
-
)
|
|
771
|
-
```
|
|
674
|
+
## Sorbet
|
|
772
675
|
|
|
773
|
-
|
|
676
|
+
This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
|
|
774
677
|
|
|
775
|
-
|
|
678
|
+
You can provide typesafe request parameters like so:
|
|
776
679
|
|
|
777
680
|
```ruby
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
schema: nil
|
|
681
|
+
image_kit.files.upload(
|
|
682
|
+
file: File.read("/path/to/file.jpg"),
|
|
683
|
+
file_name: "file-name.jpg"
|
|
782
684
|
)
|
|
783
685
|
```
|
|
784
686
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
Delete custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field)
|
|
687
|
+
Or, equivalently:
|
|
788
688
|
|
|
789
689
|
```ruby
|
|
790
|
-
|
|
791
|
-
|
|
690
|
+
# Hashes work, but are not typesafe:
|
|
691
|
+
image_kit.files.upload(
|
|
692
|
+
file: File.read("/path/to/file.jpg"),
|
|
693
|
+
file_name: "file-name.jpg"
|
|
792
694
|
)
|
|
793
|
-
```
|
|
794
|
-
|
|
795
|
-
## Access request-id, other response headers and HTTP status code
|
|
796
|
-
|
|
797
|
-
Each media management function returns a hash with `response`, `error`, `status_code`, `headers`, `raw_body` keys with respective values.
|
|
798
695
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
folder: '/test',
|
|
804
|
-
response_fields: 'tags,customCoordinates,isPrivateFile,metadata',
|
|
805
|
-
tags: %w[abc def],
|
|
806
|
-
use_unique_file_name: false,
|
|
807
|
-
is_private_file: true
|
|
696
|
+
# You can also splat a full Params class:
|
|
697
|
+
params = Imagekitio::FileUploadParams.new(
|
|
698
|
+
file: File.read("/path/to/file.jpg"),
|
|
699
|
+
file_name: "file-name.jpg"
|
|
808
700
|
)
|
|
809
|
-
|
|
810
|
-
puts upload[:headers]
|
|
811
|
-
|
|
812
|
-
# {
|
|
813
|
-
# "access-control-allow-origin"=>["*"],
|
|
814
|
-
# "x-ik-requestid"=>["6963194e-014f-8945-b05a-bdb0e088f1bd"],
|
|
815
|
-
# "content-type"=>["application/json; charset=utf-8"],
|
|
816
|
-
# "content-length"=>["611"],
|
|
817
|
-
# "etag"=>["W/\"859-GOeZiRFGOZERjHBgRUhG0EGcODs\""],
|
|
818
|
-
# "date"=>["Wed, 29 Jun 2022 07:04:33 GMT"],
|
|
819
|
-
# "x-request-id"=>["6963194e-014f-8945-b05a-bdb0e088f1bd"],
|
|
820
|
-
# "connection"=>["close"]
|
|
821
|
-
# }
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
puts upload[:raw_body]
|
|
825
|
-
# "{\"fileId\":\"62bjf980rb886bd691b86760\",\"name\":\"default.jpg\",\"size\":102117,\"versionInfo\":{\"id\":\"62bjf980rb886bd691b86760\",\"name\":\"Version 1\"},\"filePath\":\"/test/default.jpg\",\"url\":\"https://ik.imagekit.io/46865sdf6sdf/test/default.jpg\",\"fileType\":\"image\",\"height\":700,\"width\":1050,\"thumbnailUrl\":\"https://ik.imagekit.io/46865sdf6sdf/tr:n-ik_ml_thumbnail/test/default.jpg\",\"tags\":[\"abc\",\"def\"],\"AITags\":null,\"isPrivateFile\":true,\"customCoordinates\":null,\"metadata\":{\"height\":700,\"width\":1050,\"size\":102117,\"format\":\"jpg\",\"hasColorProfile\":true,\"quality\":0,\"density\":72,\"hasTransparency\":false,\"exif\":{},\"pHash\":\"90249d9b1fc74367\"}}"
|
|
701
|
+
image_kit.files.upload(**params)
|
|
826
702
|
```
|
|
827
703
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
We have included the following commonly used utility functions in this package.
|
|
831
|
-
|
|
832
|
-
**Authentication parameter generation**
|
|
833
|
-
|
|
834
|
-
If you are looking to implement client-side file upload, you will need a `token`, `expiry` timestamp, and a valid `signature` for that upload. The SDK provides a simple method that you can use in your code to generate these authentication parameters for you.
|
|
835
|
-
|
|
836
|
-
_Note: The Private API Key should never be exposed in any client-side code. You must always generate these authentication parameters on the server-side_
|
|
837
|
-
|
|
838
|
-
`authentication_parameters = imagekit.get_authentication_parameters(token, expire)`
|
|
704
|
+
### Enums
|
|
839
705
|
|
|
840
|
-
|
|
706
|
+
Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
|
|
841
707
|
|
|
842
708
|
```ruby
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
"expire": "valid_expiry_timestamp",
|
|
846
|
-
"signature": "generated_signature"
|
|
847
|
-
}
|
|
848
|
-
```
|
|
849
|
-
|
|
850
|
-
Both the `token` and `expire` parameters are optional. If not specified, the SDK uses the uuid to generate a random token and also generates a valid expiry timestamp internally. The value of the `token` and `expire` used to generate the signature is always returned in the response, no matter if they are provided as an input to this method or not.
|
|
851
|
-
|
|
852
|
-
**Distance calculation between two pHash values**
|
|
853
|
-
|
|
854
|
-
Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on the contents
|
|
855
|
-
of an image. [imagekit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the pHash
|
|
856
|
-
value of an image in the response. You can use this value to find a duplicate near the duplicate(similar) image by calculating
|
|
857
|
-
the distance between the two images.
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
This SDK exposes the `phash_distance` function to calculate the distance between two pHash values. It accepts two pHash hexadecimal
|
|
861
|
-
strings and returns a numeric value indicative of the level of difference between the two images.
|
|
709
|
+
# :all
|
|
710
|
+
puts(Imagekitio::AssetListParams::FileType::ALL)
|
|
862
711
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
# fetch metadata of two uploaded image files
|
|
866
|
-
...
|
|
867
|
-
# extract pHash strings from both: say 'first_hash' and 'second_hash.'
|
|
868
|
-
...
|
|
869
|
-
# calculate the distance between them:
|
|
870
|
-
|
|
871
|
-
distance = imagekitio.phash_distance(first_hash, second_hash)
|
|
872
|
-
return distance
|
|
712
|
+
# Revealed type: `T.all(Imagekitio::AssetListParams::FileType, Symbol)`
|
|
713
|
+
T.reveal_type(Imagekitio::AssetListParams::FileType::ALL)
|
|
873
714
|
```
|
|
874
715
|
|
|
875
|
-
|
|
716
|
+
Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
|
|
876
717
|
|
|
877
718
|
```ruby
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
719
|
+
# Using the enum constants preserves the tagged type information:
|
|
720
|
+
image_kit.assets.list(
|
|
721
|
+
file_type: Imagekitio::AssetListParams::FileType::ALL,
|
|
722
|
+
# …
|
|
723
|
+
)
|
|
883
724
|
|
|
884
|
-
|
|
885
|
-
|
|
725
|
+
# Literal values are also permissible:
|
|
726
|
+
image_kit.assets.list(
|
|
727
|
+
file_type: :all,
|
|
728
|
+
# …
|
|
729
|
+
)
|
|
886
730
|
```
|
|
887
731
|
|
|
888
|
-
##
|
|
889
|
-
There are three sample apps:
|
|
890
|
-
|
|
891
|
-
* Rails application using Carrierwave
|
|
892
|
-
* Rails application using ActiveStorage
|
|
893
|
-
* Plain ruby application
|
|
894
|
-
|
|
895
|
-
Please see the sample applications in [here](https://github.com/imagekit-samples/quickstart).
|
|
732
|
+
## Versioning
|
|
896
733
|
|
|
897
|
-
|
|
734
|
+
This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
|
|
898
735
|
|
|
899
|
-
|
|
736
|
+
This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
|
|
900
737
|
|
|
901
|
-
|
|
902
|
-
- Include `ImageKitIo::CarrierWave` in uploader class(for Carrierwave).
|
|
903
|
-
- Remove `storage :imagekit_store` config from uploader.
|
|
904
|
-
- Rename class `ImageKit::ImageKitClient` to `ImageKitIo::Client`
|
|
905
|
-
- Rename class `ImageKitIo::ImageKitRequest` to `ImageKitIo::Request`
|
|
738
|
+
## Requirements
|
|
906
739
|
|
|
907
|
-
|
|
908
|
-
For any feedback or to report any issues or general implementation support, please reach out to [support@imagekit.io](mailto:support@imagekit.io)
|
|
740
|
+
Ruby 3.2.0 or higher.
|
|
909
741
|
|
|
910
|
-
##
|
|
911
|
-
- [Documentation](https://docs.imagekit.io)
|
|
912
|
-
- [Main website](https://imagekit.io)
|
|
742
|
+
## Contributing
|
|
913
743
|
|
|
914
|
-
|
|
915
|
-
Released under the MIT license.
|
|
744
|
+
See [the contributing documentation](https://github.com/imagekit-developer/imagekit-ruby/tree/master/CONTRIBUTING.md).
|