Heroku (मुश्किल तरीके से सीखा) किसी भी सर्वर अनुरोध पर 30 सेकंड की समय समाप्ति है, तो निश्चित रूप से S3 पर फ़ाइलें संग्रहीत करने के लिए जरूरी है।
पेपरक्लिप के बजाय carrierwave (carrierwave railscasts) की कोशिश करो, जैसा कि मैंने जोड़ा सहायकों कि जहाज पर आ पसंद करते हैं, के साथ साथ S3 के लिए बड़े फ़ाइल अपलोड करना, जो carrierwave के साथ अच्छी तरह से एकीकृत के लिए महान plugins की एक संख्या है, carrierwave_direct की तरह।
Delayed_job (रेलवे - delayed_job) एस 3 से फ़ाइलों को हटाने और किसी अन्य पृष्ठभूमि प्रसंस्करण की आवश्यकता के लिए अच्छी तरह से काम करेगा।
gem 'delayed_job'
gem "aws-s3", :require => 'aws/s3'
gem 'fog'
gem 'carrierwave'
gem 'carrierwave_direct'
कोहरे मणि एक ही स्थान में अपने सभी खाते की जानकारी के लिए एक अच्छा तरीका है और काफी अच्छी तरह से सब कुछ सेट:
मेरे मणि फ़ाइल में निम्नलिखित शामिल हैं। एडब्ल्यूएस मणि how-to, अच्छा संसाधन के लिए।
यहाँ जब अपलोड करने के लिए एक पर्चे को जमा करने के लिए एक नमूना नियंत्रक है (वहाँ ऐसा करने का निश्चित रूप से बेहतर तरीके हैं, लेकिन निदर्शी प्रयोजनों के लिए)
def create
@asset = Asset.new(:description => params[:description], :user_id => session[:id], :question_id => @question.id)
if @asset.save && @asset.update_attributes(:file_name => sanitize_filename(params[:uploadfile].original_filename, @asset.id))
AWS::S3::S3Object.store(sanitize_filename(params[:uploadfile].original_filename, @asset.id), params[:uploadfile].read, 'bucket_name', :access => :private, :content_type => params[:uploadfile].content_type)
if object.content_length.to_i < @question.emailatt.to_i.megabytes && object.content_length.to_i < 5.megabytes
url = AWS::S3::S3Object.url_for(sanitize_filename(params[:uploadfile].original_filename, @asset.id), 'bucket_name')
if @asset.update_attributes(:download_link => 1)
if Usermailer.delay({:run_at => 5.minutes.from_now}).attachment_user_mailer_download_notification(@asset, @question)
process_attachment_user_mailer_download(params[:uploadfile], @asset.id, 24.hours.from_now, @question.id)
flash[:notice] = "Thank you for the upload, we will notify this posts author"
end
end
end
else
@asset.destroy
flash[:notice] = "There was an error in processing your upload, please try again"
redirect_to(:controller => "questions", :action => "show", :id => @question.id)
end
end
private
def sanitize_filename(file_name, id)
just_filename = File.basename(file_name)
just_filename.sub(/[^\w\.\-]/,'_')
new_id = id.to_s
new_filename = "#{new_id}" + just_filename
end
def delete_process(uploadfile, asset_id, time, question_id)
asset = Asset.find(:first, :conditions => ["id = ?", asset_id])
if delete_file(uploadfile, asset_id, time) && asset.destroy
redirect_to(:controller => "questions", :action => "show", :id => question_id)
end
end
def process_attachment_user_mailer_download(uploadfile, asset_id, time, question_id)
asset = Asset.find(:first, :conditions => ["id = ?", asset_id])
if delete_file(uploadfile, asset_id, time) && @asset.delay({:run_at => time}).update_attributes(:download_link => 0)
redirect_to(:controller => "questions", :action => "show", :id => question_id)
end
end
#S3 METHODS FOR CREATE ACTION
#deletes the uploaded file from s3
def delete_file(uploadfile, asset_id, time)
AWS::S3::S3Object.delay({:run_at => time}).delete(sanitize_filename(uploadfile.original_filename, asset_id), 'bucket_name')
end
अनावश्यक कोड के बहुत सारे, मुझे पता है (यह लिखा जब मैं रेल के साथ शुरू हो रहा था)। उम्मीद है कि यह इस प्रकार के ऐप को लिखने में शामिल प्रक्रियाओं का कुछ विचार देगा। आशा करता हूँ की ये काम करेगा।