Class: Imagekitio::Resources::Beta::V2::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/imagekitio/resources/beta/v2/files.rb

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:



103
104
105
# File 'lib/imagekitio/resources/beta/v2/files.rb', line 103

def initialize(client:)
  @client = client
end

Instance Method Details

#upload(file: , file_name: , token: nil, checks: nil, custom_coordinates: nil, custom_metadata: nil, description: 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, response_fields: nil, tags: nil, transformation: nil, use_unique_file_name: nil, webhook_url: nil, request_options: {}) ⇒ Imagekitio::Models::Beta::V2::FileUploadResponse

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

The V2 API enhances security by verifying the entire payload using JWT. This API is in beta.

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` from your secure backend using private API. [Learn more](/docs/api-reference/upload-file/upload-file-v2#how-to-implement-secure-client-side-file-upload) about how to implement secure client-side file upload.

**File size limit** \ On the free plan, the maximum upload file sizes are 20MB for images, audio, and raw files, and 100MB for videos. On the paid plan, these limits increase to 40MB for images, audio, and raw files, and 2GB for videos. These limits can be further increased with higher-tier 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)

    This is the client-generated JSON Web Token (JWT). The ImageKit.io server uses i

  • 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.

  • extensions (Array<Imagekitio::Models::ExtensionItem::RemoveBg, Imagekitio::Models::ExtensionItem::AIAutoDescription, 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

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

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

  • tags (Array<String>)

    Set the tags while uploading the file.

  • transformation (Imagekitio::Models::Beta::V2::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:



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/imagekitio/resources/beta/v2/files.rb', line 86

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