Class: Imagekitio::Resources::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/imagekitio/resources/files.rb,
lib/imagekitio/resources/files/bulk.rb,
lib/imagekitio/resources/files/metadata.rb,
lib/imagekitio/resources/files/versions.rb

Defined Under Namespace

Classes: Bulk, Metadata, Versions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Files

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Files.

Parameters:



293
294
295
296
297
298
# File 'lib/imagekitio/resources/files.rb', line 293

def initialize(client:)
  @client = client
  @bulk = Imagekitio::Resources::Files::Bulk.new(client: client)
  @versions = Imagekitio::Resources::Files::Versions.new(client: client)
  @metadata = Imagekitio::Resources::Files::Metadata.new(client: client)
end

Instance Attribute Details

#bulkImagekitio::Resources::Files::Bulk (readonly)



7
8
9
# File 'lib/imagekitio/resources/files.rb', line 7

def bulk
  @bulk
end

#metadataImagekitio::Resources::Files::Metadata (readonly)



13
14
15
# File 'lib/imagekitio/resources/files.rb', line 13

def 
  @metadata
end

#versionsImagekitio::Resources::Files::Versions (readonly)



10
11
12
# File 'lib/imagekitio/resources/files.rb', line 10

def versions
  @versions
end

Instance Method Details

#copy(destination_path:, source_file_path:, include_file_versions: nil, request_options: {}) ⇒ Imagekitio::Models::FileCopyResponse

Some parameter documentations has been truncated, see Models::FileCopyParams for more details.

This will copy a file from one folder to another.

Note: If any file at the destination has the same name as the source file, then the source file and its versions (if ‘includeFileVersions` is set to true) will be appended to the destination file version history.

Parameters:

  • destination_path (String)

    Full path to the folder you want to copy the above file into.

  • source_file_path (String)

    The full path of the file you want to copy.

  • include_file_versions (Boolean)

    Option to copy all versions of a file. By default, only the current version of t

  • request_options (Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



93
94
95
96
97
98
99
100
101
102
# File 'lib/imagekitio/resources/files.rb', line 93

def copy(params)
  parsed, options = Imagekitio::FileCopyParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/files/copy",
    body: parsed,
    model: Imagekitio::Models::FileCopyResponse,
    options: options
  )
end

#delete(file_id, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::FileDeleteParams for more details.

This API deletes the file and all its file versions permanently.

Note: If a file or specific transformation has been requested in the past, then the response is cached. Deleting a file does not purge the cache. You can purge the cache using purge cache API.

Parameters:

  • file_id (String)

    The unique ‘fileId` of the uploaded file. `fileId` is returned in list and searc

  • request_options (Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



62
63
64
65
66
67
68
69
# File 'lib/imagekitio/resources/files.rb', line 62

def delete(file_id, params = {})
  @client.request(
    method: :delete,
    path: ["v1/files/%1$s", file_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#get(file_id, request_options: {}) ⇒ Imagekitio::Models::File

Some parameter documentations has been truncated, see Models::FileGetParams for more details.

This API returns an object with details or attributes about the current version of the file.

Parameters:

  • file_id (String)

    The unique ‘fileId` of the uploaded file. `fileId` is returned in the list and s

  • request_options (Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



119
120
121
122
123
124
125
126
# File 'lib/imagekitio/resources/files.rb', line 119

def get(file_id, params = {})
  @client.request(
    method: :get,
    path: ["v1/files/%1$s/details", file_id],
    model: Imagekitio::File,
    options: params[:request_options]
  )
end

#move(destination_path:, source_file_path:, request_options: {}) ⇒ Imagekitio::Models::FileMoveResponse

Some parameter documentations has been truncated, see Models::FileMoveParams for more details.

This will move a file and all its versions from one folder to another.

Note: If any file at the destination has the same name as the source file, then the source file and its versions will be appended to the destination file.

Parameters:

  • destination_path (String)

    Full path to the folder you want to move the above file into.

  • source_file_path (String)

    The full path of the file you want to move.

  • request_options (Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



147
148
149
150
151
152
153
154
155
156
# File 'lib/imagekitio/resources/files.rb', line 147

def move(params)
  parsed, options = Imagekitio::FileMoveParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/files/move",
    body: parsed,
    model: Imagekitio::Models::FileMoveResponse,
    options: options
  )
end

#rename(file_path:, new_file_name:, purge_cache: nil, request_options: {}) ⇒ Imagekitio::Models::FileRenameResponse

Some parameter documentations has been truncated, see Models::FileRenameParams for more details.

You can rename an already existing file in the media library using rename file API. This operation would rename all file versions of the file.

Note: The old URLs will stop working. The file/file version URLs cached on CDN will continue to work unless a purge is requested.

Parameters:

  • file_path (String)

    The full path of the file you want to rename.

  • new_file_name (String)

    The new name of the file. A filename can contain:

  • purge_cache (Boolean)

    Option to purge cache for the old file and its versions’ URLs.

  • request_options (Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



180
181
182
183
184
185
186
187
188
189
# File 'lib/imagekitio/resources/files.rb', line 180

def rename(params)
  parsed, options = Imagekitio::FileRenameParams.dump_request(params)
  @client.request(
    method: :put,
    path: "v1/files/rename",
    body: parsed,
    model: Imagekitio::Models::FileRenameResponse,
    options: options
  )
end

#update(file_id, update_file_request:, request_options: {}) ⇒ Imagekitio::Models::FileUpdateResponse

Some parameter documentations has been truncated, see Models::FileUpdateParams for more details.

This API updates the details or attributes of the current version of the file. You can update ‘tags`, `customCoordinates`, `customMetadata`, publication status, remove existing `AITags` and apply extensions using this API.

Parameters:

Returns:

See Also:



33
34
35
36
37
38
39
40
41
42
# File 'lib/imagekitio/resources/files.rb', line 33

def update(file_id, params)
  parsed, options = Imagekitio::FileUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["v1/files/%1$s/details", file_id],
    body: parsed[:update_file_request],
    model: Imagekitio::Models::FileUpdateResponse,
    options: options
  )
end

#upload(file:, file_name:, token: nil, checks: nil, custom_coordinates: nil, custom_metadata: nil, description: nil, expire: nil, extensions: nil, folder: nil, is_private_file: nil, is_published: nil, overwrite_ai_tags: nil, overwrite_custom_metadata: nil, overwrite_file: nil, overwrite_tags: nil, public_key: nil, response_fields: nil, signature: nil, tags: nil, transformation: nil, use_unique_file_name: nil, webhook_url: nil, request_options: {}) ⇒ Imagekitio::Models::FileUploadResponse

Some parameter documentations has been truncated, see Models::FileUploadParams for more details.

ImageKit.io allows you to upload files directly from both the server and client sides. For server-side uploads, private API key authentication is used. For client-side uploads, generate a one-time ‘token`, `signature`, and `expire` from your secure backend using private API. [Learn more](/docs/api-reference/upload-file/upload-file#how-to-implement-client-side-file-upload) about how to implement client-side file upload.

The [V2 API](/docs/api-reference/upload-file/upload-file-v2) enhances security by verifying the entire payload using JWT.

**File size limit** \ On the free plan, the maximum upload file sizes are 25MB for images, audio, and raw files and 100MB for videos. On the Lite paid plan, these limits increase to 40MB for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan, these limits increase to 50MB for images, audio, and raw files and 2GB for videos. These limits can be further increased with enterprise plans.

**Version limit** \ A file can have a maximum of 100 versions.

**Demo applications**

  • A full-fledged [upload widget using Uppy](github.com/imagekit-samples/uppy-uploader), supporting file selections from local storage, URL, Dropbox, Google Drive, Instagram, and more.

  • [Quick start guides](/docs/quick-start-guides) for various frameworks and technologies.

Parameters:

  • file (Pathname, StringIO, IO, String, Imagekitio::FilePart)

    The API accepts any of the following:

  • file_name (String)

    The name with which the file has to be uploaded.

  • token (String)

    A unique value that the ImageKit.io server will use to recognize and prevent sub

  • checks (String)

    Server-side checks to run on the asset.

  • custom_coordinates (String)

    Define an important area in the image. This is only relevant for image type file

  • custom_metadata (Hash{Symbol=>Object})

    JSON key-value pairs to associate with the asset. Create the custom metadata fie

  • description (String)

    Optional text to describe the contents of the file.

  • expire (Integer)

    The time until your signature is valid. It must be a [Unix time](en.wiki

  • extensions (Array<Imagekitio::Models::ExtensionItem::RemoveBg, Imagekitio::Models::ExtensionItem::AIAutoDescription, Imagekitio::Models::ExtensionItem::AITasks, Imagekitio::Models::ExtensionItem::SavedExtension, Imagekitio::Models::ExtensionItem::AutoTaggingExtension>)

    Array of extensions to be applied to the asset. Each extension can be configured

  • folder (String)

    The folder path in which the image has to be uploaded. If the folder(s) didn’t e

  • is_private_file (Boolean)

    Whether to mark the file as private or not.

  • is_published (Boolean)

    Whether to upload file as published or not.

  • overwrite_ai_tags (Boolean)

    If set to ‘true` and a file already exists at the exact location, its AITags wil

  • overwrite_custom_metadata (Boolean)

    If the request does not have ‘customMetadata`, and a file already exists at the

  • overwrite_file (Boolean)

    If ‘false` and `useUniqueFileName` is also `false`, and a file already exists at

  • overwrite_tags (Boolean)

    If the request does not have ‘tags`, and a file already exists at the exact loca

  • public_key (String)

    Your ImageKit.io public key. This field is only required for authentication when

  • response_fields (Array<Symbol, Imagekitio::Models::FileUploadParams::ResponseField>)

    Array of response field keys to include in the API response body.

  • signature (String)

    HMAC-SHA1 digest of the token+expire using your ImageKit.io private API key as a

  • tags (Array<String>)

    Set the tags while uploading the file.

  • transformation (Imagekitio::Models::FileUploadParams::Transformation)

    Configure pre-processing (‘pre`) and post-processing (`post`) transformations.

  • use_unique_file_name (Boolean)

    Whether to use a unique filename for this file or not.

  • webhook_url (String)

    The final status of extensions after they have completed execution will be deliv

  • request_options (Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/imagekitio/resources/files.rb', line 276

def upload(params)
  parsed, options = Imagekitio::FileUploadParams.dump_request(params)
  path =
    @client.base_url_overridden? ? "api/v1/files/upload" : "https://upload.imagekit.io/api/v1/files/upload"
  @client.request(
    method: :post,
    path: path,
    headers: {"content-type" => "multipart/form-data"},
    body: parsed,
    model: Imagekitio::Models::FileUploadResponse,
    options: options
  )
end