Created
May 26, 2014 08:55
-
-
Save romanonthego/f9fa5aa073502adc3699 to your computer and use it in GitHub Desktop.
old gem solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You could do it before, after save or in any place you want | |
before_save do | |
# build i file if you want to check something with it first | |
file = @api.file(self."#{file_attribute}") | |
if file.something ... | |
url = file.cdn_url | |
end | |
# or use bare url widget passed to you from web form | |
url = self."#{file_attribute}" | |
# it is important to wrap it up in case remote call fails for any reason | |
begin | |
response = @api.request :post, "/files/", {:source => url, :target => "#{s3_target_url}"} | |
# { | |
# "url" : "http://..." | |
# } | |
# do that you must. it is basicly JSON string. | |
rescue | |
# in case everything fails. | |
# it is not happens very ofter but your application can not depends on server status of any other server, right? | |
# you may put it to query to call again in five minutes in separate process for example | |
logger.error "#{error text}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment