class Uploadcare::Entity::File

This serializer returns a single file

@see uploadcare.com/docs/api_reference/rest/handling_projects/

Public Class Methods

copy(source, **args) click to toggle source

'copy' method is used to copy original files or their modified versions to default storage.

Source files MAY either be stored or just uploaded and MUST NOT be deleted.

@param [String] source uuid or uploadcare link to file. @param [Hash] args @option args [Boolean] :store Whether to store the file @option args [Boolean] :strip_operations Copies file without transformations (if source has them) @option args [String] :target points to a target custom storage. @option args [Boolean] :make_public make files on custom storage available via public links. @option args [String] :pattern define file naming pattern for the custom storage scenario.

@see uploadcare.com/api-refs/rest-api/v0.5.0/#operation/copyFile

# File lib/uploadcare/entity/file.rb, line 42
def self.copy(source, **args)
  response = FileClient.new.copy(source: source, **args).success[:result]
  File.new(response)
end
local_copy(source, **args) click to toggle source

Copies file to current project

source can be UID or full CDN link

@see .copy

# File lib/uploadcare/entity/file.rb, line 52
def self.local_copy(source, **args)
  File.copy(source, **args)
end
remote_copy(source, target, **args) click to toggle source

copy file to different project

source can be UID or full CDN link

@see .copy

# File lib/uploadcare/entity/file.rb, line 61
def self.remote_copy(source, target, **args)
  File.copy(source: source, target: target, **args)
end

Public Instance Methods

copy(**args) click to toggle source

Instance version of #{copy}. Copies current file.

# File lib/uploadcare/entity/file.rb, line 66
def copy(**args)
  File.copy(uuid, **args)
end
load() click to toggle source

loads file metadata, if it's initialized with url or uuid

# File lib/uploadcare/entity/file.rb, line 25
def load
  initialize(File.info(uuid).entity)
end
local_copy(**args) click to toggle source

Instance version of {internal_copy}

# File lib/uploadcare/entity/file.rb, line 71
def local_copy(**args)
  File.local_copy(uuid, **args)
end
remote_copy(target, **args) click to toggle source

Instance version of {external_copy}

# File lib/uploadcare/entity/file.rb, line 76
def remote_copy(target, **args)
  File.copy(uuid, target: target, **args)
end
uuid() click to toggle source

gets file's uuid - even if it's only initialized with url @return [String]

# File lib/uploadcare/entity/file.rb, line 16
def uuid
  return @entity.uuid if @entity.uuid

  uuid = @entity.url.gsub('https://ucarecdn.com/', '')
  uuid = uuid.gsub(%r{\/.*}, '')
  uuid
end