开发者

nginx upload module

I am having some trouble getting the nginx upload module working with my rails application.

my route

     match 开发者_开发知识库'/images/fast_upload' => 'images#create', :via => :post

image model

   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;
  }

In the controller my create method

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

Basically I'm not sure how to get this create method to use nginx to upload. I tried to use @image = @resource.current_user.images.build(params[:image]) but that was giving me an undefined method error.


What you should check is what parameters nginx passes when creating the upload. I have the same logic like you do. The create action i've got is as follows. Bear with me because i'm not able to test the parameters nginx passes now. But I think it's not "image" but "upload"

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

Is my create method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜