class Uploadcare::Entity::File
This serializer returns a single file
@see uploadcare.com/docs/api_reference/rest/handling_projects/
Public Class Methods
'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
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
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
Instance version of #{copy}. Copies current file.
# File lib/uploadcare/entity/file.rb, line 66 def copy(**args) File.copy(uuid, **args) end
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
Instance version of {internal_copy}
# File lib/uploadcare/entity/file.rb, line 71 def local_copy(**args) File.local_copy(uuid, **args) end
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
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