Class: Scrivito::Binary

Inherits:
Object
  • Object
show all
Defined in:
lib/scrivito/binary.rb

Overview

The Binary class represents the data stored in a binary attribute of an Obj or Widget

Instance Method Summary collapse

Instance Method Details

#content_lengthInteger

the length of this binary data, in bytes.

Returns:

  • (Integer)

    number of bytes



52
53
54
# File 'lib/scrivito/binary.rb', line 52

def content_length
  headers[:content_length].to_i
end

#content_typeString

the content type of this binary data, for example “image/jpeg”

Returns:

  • (String)

    content type



45
46
47
# File 'lib/scrivito/binary.rb', line 45

def content_type
  headers[:content_type]
end

#filenameString

the filename of this binary data, for example “my_image.jpg”

Returns:

  • (String)

    the filename of binary



38
39
40
# File 'lib/scrivito/binary.rb', line 38

def filename
  File.basename(URI(url).path)
end

#private?Boolean

Some Scrivito data is considered private, i.e. it is not currently intended for the general public, for example content in a workspace that has not been published yet.

Returns:

  • (Boolean)


19
20
21
# File 'lib/scrivito/binary.rb', line 19

def private?
  !public_content?
end

#urlString

The URL where this binary data is accessible and can be downloaded using an HTTP GET request. Note that urls for private content will have an expiration time in order to protect them. Therefore the url returned here should be accessed immediately after it has been returned (i.e. within a couple of minutes). When accessed after they have expired, an error will occur. The urls should not be used for long-term-storage (i.e. they are no longer accessible hours or days after they have been generated).

Returns:

  • (String)

    the URL under which this content is available



31
32
33
# File 'lib/scrivito/binary.rb', line 31

def url
  find_url('get')
end