Class: CarrierWave::Storage::CloudFiles::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/cloud_files.rb

Instance Method Summary collapse

Constructor Details

#initialize(uploader, base, path) ⇒ File

Returns a new instance of File.



29
30
31
32
33
# File 'lib/carrierwave/storage/cloud_files.rb', line 29

def initialize(uploader, base, path)
  @uploader = uploader
  @path = path
  @base = base
end

Instance Method Details

#content_typeObject



82
83
84
# File 'lib/carrierwave/storage/cloud_files.rb', line 82

def content_type
  cf_container.object(@path).content_type
end

#content_type=(new_content_type) ⇒ Object



86
87
88
# File 'lib/carrierwave/storage/cloud_files.rb', line 86

def content_type=(new_content_type)
  headers["content-type"] = new_content_type
end

#deleteObject

Remove the file from Cloud Files



62
63
64
# File 'lib/carrierwave/storage/cloud_files.rb', line 62

def delete
  cf_container.delete_object(@path)
end

#pathObject

Returns the current path/filename of the file on Cloud Files.

Returns

String

A path



42
43
44
# File 'lib/carrierwave/storage/cloud_files.rb', line 42

def path
  @path
end

#readObject

Reads the contents of the file from Cloud Files

Returns

String

contents of the file



53
54
55
56
57
# File 'lib/carrierwave/storage/cloud_files.rb', line 53

def read
  object = cf_container.object(@path)
  @content_type = object.content_type
  object.data
end

#store(data, headers = {}) ⇒ Object

Writes the supplied data into the object on Cloud Files.

Returns

boolean



97
98
99
100
# File 'lib/carrierwave/storage/cloud_files.rb', line 97

def store(data,headers={})
  object = cf_container.create_object(@path)
  object.write(data,headers)
end

#urlObject

Returns the url on the Cloud Files CDN. Note that the parent container must be marked as public for this to work.

Returns

String

file’s url



74
75
76
77
78
79
80
# File 'lib/carrierwave/storage/cloud_files.rb', line 74

def url
  if @uploader.cloud_files_cdn_host
    "http://" + @uploader.cloud_files_cdn_host + "/" + @path
  else
    cf_container.object(@path).public_url
  end
end