This is a sample which uploads a remote file to the CMS storage (local or aws):
# lib/tasks/owen.rake
namespace :owen do
desc "Test download external image"
task download_image: :environment do
include Rails.application.routes.url_helpers
include CamaleonCms::SiteHelper
include CamaleonCms::HooksHelper
include CamaleonCms::UploaderHelper
def current_site; CamaleonCms::Site.first.decorate; end
result = upload_file('https://images.onset.freedom.com/ocregister/gallery/onn96a-top10groups2017.jpg')
# sample result: {"name"=>"onn96a_top10groups2017_7.jpg", "key"=>"/onn96a_top10groups2017_7.jpg", "url"=>"https://localhost:3000/media/1/onn96a_top10groups2017_7.jpg", "is_folder"=>false, "size"=>35255.0, "format"=>"image", "deleteUrl"=>"", "thumb"=>"https://localhost:3000/media/1/thumb/onn96a_top10groups2017_7-jpg.jpg", "type"=>"image/jpeg", "created_at"=>2017-04-05 10:46:25 -0400, "dimension"=>"560x420"}
end
end
Note: to upload a local file, you can do it like:
result = upload_file(File.open('/myfolder/my_file.txt'))
To run the example:
rake owen:download_image
Created at: 05 Apr 11:46 | Updated at: 05 Apr 11:52