Paperclip Post请求不上传图片

时间:2016-04-01 18:14:55

标签: ruby-on-rails paperclip

我正在尝试通过回形针上的帖子请求上传图片。

我成功执行了请求,但请求没有上传图片。

我的照片模型

class Picture < ActiveRecord::Base
    attr_accessor :images, :images_file_name
   has_attached_file :images  
   do_not_validate_attachment_file_type :images                                  
end

我的控制器

class PicturesController < ApplicationController     
  def event_desc_image
    @image_url = Picture.create!(images: params[:images])             
    render :json => @image_url      
  end      
end

在rails控制台中触发命令

[paperclip] saving /pictures/images/000/000/004/original/tcs.png
[AWS S3 200 3.948386 0 retries] put_object(:acl=>:public_read,:bucket_name=>"clot1",:content_length=>88200,:content_type=>"image/png",:data=>Paperclip::UploadedFileAdapter: tcs.png,:key=>"pictures/images/000/000/004/original/tcs.png")  

[paperclip] saving /pictures/images/000/000/004/medium/tcs.png
[AWS S3 200 0.878744 0 retries] put_object(:acl=>:public_read,:bucket_name=>"clot1",:content_length=>24067,:content_type=>"image/png",:data=>Paperclip::FileAdapter: f3dfe432021081dc257184b8a895464420160401-4627-1usx855,:key=>"pictures/images/000/000/004/medium/tcs.png")  

[paperclip] saving /pictures/images/000/000/004/thumb/tcs.png
[AWS S3 200 0.560126 0 retries] put_object(:acl=>:public_read,:bucket_name=>"clot1",:content_length=>4416,:content_type=>"image/png",:data=>Paperclip::FileAdapter: f3dfe432021081dc257184b8a895464420160401-4627-ui906j,:key=>"pictures/images/000/000/004/thumb/tcs.png") 

但它没有保存任何图像数据。 对象看起来像:

+----+-----------------+--------------------+-----------------+------------------+-------------------------+-------------------------+---------+
| id | image_file_name | image_content_type | image_file_size | image_updated_at | created_at              | updated_at              | caption |
+----+-----------------+--------------------+-----------------+------------------+-------------------------+-------------------------+---------+
| 1  |                 |                    |                 |                  | 2016-04-01 17:55:05 UTC | 2016-04-01 17:55:05 UTC |         |
-------+-------------------------+-------------------------+---------+

请建议解决方案。 感谢

3 个答案:

答案 0 :(得分:1)

将图片添加到图片控制器中的允许参数列表中。

答案 1 :(得分:0)

以下解决方案

class PicturesController < ApplicationController 

  def event_desc_image
    @image = Picture.create!(photo_params)             
    render :json => @image      
  end

  private

  def photo_params
    params.permit(:image)
  end

end

谢谢@Brian

答案 2 :(得分:-1)

你看到了什么:

IJavaScriptExecutor executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("arguments[0].click();", ElementToClick)

as event_desc_image第一行?

相关问题