Skip to content

@nathancolgate /gist:575842
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
// 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'
}
)
};
// The action
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
// Then in my upload model
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
Something went wrong with that request. Please try again.