Method: Scrivito::Binary#copy

Defined in:
app/cms/scrivito/binary.rb

#copy(options = {}) ⇒ Scrivito::FutureBinary

Create a copy of this Binary with a different filename and/or content type.

Examples:

Change filename and content_type of an existing binary. Binary content remains the same.

@obj.update(blob: @obj.blob.copy(filename: "cute_kitten.jpg", content_type: "video/mp4"))

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • filename (String)

    the desired filename. Defaults to the filename of the original binary.

  • content_type (String)

    the desired content type. By default, the content type is calculated based on the extension of the filename.

Returns:

Raises:

  • ArgumentError if given filename or content_type is blank.



91
92
93
94
# File 'app/cms/scrivito/binary.rb', line 91

def copy(options = {})
  self.class.assert_valid_options(options)
  FutureBinary.new(options.reverse_merge(filename: self.filename, id_to_copy: id))
end