Skip to content

Instantly share code, notes, and snippets.

@bullfight
Created August 22, 2011 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bullfight/1162410 to your computer and use it in GitHub Desktop.
Save bullfight/1162410 to your computer and use it in GitHub Desktop.
// This is my handler in the javascript
var uploadCompleteHandler = function(upload_options,event){
$.ajax({
url: '<%= notify_rails_of_successful_upload_path(:format => :js)%>',
global: false,
type: 'POST',
data: ({
'authenticity_token' : '<%= form_authenticity_token %>',
'upload' : {
'file_file_name' : upload_options.FileName,
'file_file_size' : upload_options.FileSize,
'file_content_type' : upload_options.ContentType
}
}),
dataType: 'script'
}
)
};
def swf_create
@upload = Upload.new(params[:upload])
respond_to do |format|
if @upload.save
format.js { } # crazy cool stuff here
else
format.js { render :text => 'alert("Failure from Rails!");' }
end
end
end
after_create :move_upload_from_temp_to_final_resting_place
def move_upload_from_temp_to_final_resting_place
# Rename the image on s3 (more of a move)
AWS::S3::Base.establish_connection!(:access_key_id => S3Config[:access_key_id],:secret_access_key => S3Config[:secret_access_key])
new_name = self.file.path
old_name = "temp/#{self.file_file_name}"
(1..5).each do |try|
begin
# Copy the file
AWS::S3::S3Object.rename(old_name, new_name, S3Config[:bucket], :copy_acl => :true)
break
rescue Exception => e
sleep 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment