nginx上传模块

问题描述:

我在使用我的rails应用程序获取nginx上传模块时遇到了一些麻烦。nginx上传模块

我的行程

 match '/images/fast_upload' => 'images#create', :via => :post 

图像模型

attr_accessor :tmp_upload_dir 
    after_create :clean_tmp_upload_dir 


    # handle new param 
    def fast_asset=(file) 
     if file && file.respond_to?('[]') 
     self.tmp_upload_dir = "#{file['filepath']}_1" 
     tmp_file_path = "#{self.tmp_upload_dir}/#{file['original_name']}" 
     FileUtils.mkdir_p(self.tmp_upload_dir) 
     FileUtils.mv(file['filepath'], tmp_file_path) 
     self.asset = File.new(tmp_file_path) 
     end 
    end  

private 
# clean tmp directory used in handling new param 
    def clean_tmp_upload_dir 
    FileUtils.rm_r(tmp_upload_dir) if self.tmp_upload_dir && File.directory? (self.tmp_upload_dir) 
    end   

nginx.conf

upload_pass @fast_upload_endpoint; 


    upload_store /pathto/shared/uploads_tmp 1; 


    upload_store_access user:rw group:rw all:r; 


    upload_set_form_field upload[fast_asset][original_name] "$upload_file_name"; 
    upload_set_form_field upload[fast_asset][content_type] "$upload_content_type"; 
    upload_set_form_field upload[fast_asset][filepath] "$upload_tmp_path"; 

    upload_pass_form_field "^image_id$|^authenticity_token$|^format$"; 
    upload_cleanup 400 404 499 500-505; 
    } 

    location @fast_upload_endpoint { 

    passenger_enabled on; 
    rails_env production; 
    } 

    location/{ 
    rails_env production; 
    passenger_enabled on; 
    } 

在控制器我的创建方法

def create 
    @image = current_user.images.build(params[:image]) 
    if @image.save 

基本上我不知道如何让这个创建方法使用nginx上传。我试图使用@image = @ resource.current_user.images.build(params [:image]),但那给了我一个未定义的方法错误。

你应该检查什么是创建上传时nginx传递的参数。我有和你一样的逻辑。我得到的创建操作如下。忍受我,因为我无法现在测试参数nginx通行证。但我认为这不是“图像”,而是“上传”

@photo = @artist.photos.build(params[:upload]) 

是我的创建方法。