class CarrierWave::Storage::Sharefile::File

Attributes

path[R]

Public Class Methods

new(uploader, config, path, client) click to toggle source
# File lib/carrierwave/storage/sharefile.rb, line 45
def initialize(uploader, config, path, client)
  @uploader, @config, @path, @client = uploader, config, path, client
end

Public Instance Methods

content_type() click to toggle source

Lookup value for file content-type header

Returns

String

value of content-type

# File lib/carrierwave/storage/sharefile.rb, line 71
def content_type
  @content_type || file.content_type
end
content_type=(new_content_type) click to toggle source

Set non-default content-type header (default is file.content_type)

Returns

String

returns new content type value

# File lib/carrierwave/storage/sharefile.rb, line 82
def content_type=(new_content_type)
  @content_type = new_content_type
end
delete() click to toggle source

Removes a file from the service

Returns

Boolean

true on success or raises error

# File lib/carrierwave/storage/sharefile.rb, line 118
def delete
  @client.delete_document(@path)
end
filename() click to toggle source
# File lib/carrierwave/storage/sharefile.rb, line 49
def filename
  Pathname.new(path).basename.to_s
end
read() click to toggle source

Read content of file from service

Returns

String

contents of file

# File lib/carrierwave/storage/sharefile.rb, line 92
def read
  file
end
retrieve(identifier) click to toggle source

Retrieve file from service

Returns

File
# File lib/carrierwave/storage/sharefile.rb, line 143
def retrieve(identifier)
  @file = @client.get_document(identifier)
  @file ||= @file.parsed_response
end
sharefile_attributes() click to toggle source
# File lib/carrierwave/storage/sharefile.rb, line 107
def sharefile_attributes
  attributes
end
size() click to toggle source

Return size of file body

Returns

Integer

size of file body

# File lib/carrierwave/storage/sharefile.rb, line 103
def size
  file.content_length
end
store(file) click to toggle source

Write file to service

Returns

Boolean

true on success or raises error

# File lib/carrierwave/storage/sharefile.rb, line 129
def store(file)
  sharefile_file = file.to_file
  @content_type ||= file.content_type
  root_folder = @config[:sharefile_root]
  @file = @client.store_document(root_folder, @path, sharefile_file)
end
url() click to toggle source

Lookup URL for the path

Returns

String

URL of the download link

# File lib/carrierwave/storage/sharefile.rb, line 60
def url
  @client.get_download_link(@path)
end