lib/carrierwave/storage/sftp.rb in carrierwave-ftp-0.2.0 vs lib/carrierwave/storage/sftp.rb in carrierwave-ftp-0.2.1
- old
+ new
@@ -49,13 +49,21 @@
def exists?
size ? true : false
end
def read
- http_get_body(url)
+ file.body
end
+ def content_type
+ @content_type || file.content_type
+ end
+
+ def content_type=(new_content_type)
+ @content_type = new_content_type
+ end
+
def delete
connection do |sftp|
sftp.remove!(full_path)
end
end
@@ -64,18 +72,16 @@
def full_path
"#{@uploader.sftp_folder}/#{path}"
end
- def http_get_body(url)
+ def file
require 'net/http'
url = URI.parse(url)
req = Net::HTTP::Get.new(url.path)
- res = Net::HTTP.start(url.host, url.port) do |http|
+ Net::HTTP.start(url.host, url.port) do |http|
http.request(req)
end
-
- res.body
end
def connection
sftp = Net::SFTP.start(@uploader.sftp_host, @uploader.sftp_user, @uploader.sftp_options)
yield sftp