2016-04-01 12 views
1

私はポストクリップで画像をアップロードしようとしています。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 

は、コマンド

[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 |   | 
-------+-------------------------+-------------------------+---------+ 

解決策をご提案ください。 ありがとう

+0

@Brian

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 

おかげであなたが許可したの働いていましたか? –

+0

私はattr_accessorを使用しています – Adt

答えて

1

画像コントローラの許可されたパラメータリストに画像を追加します。

+0

次の形式のパラメータを取得するので、私はそれを行うことができません: パラメータ:{"images" =># Adt

-1

あなたが何を参照してください:event_desc_image最初の行として

return render json: params 

?コントローラでのparamsの画像:解決後

0

+0

iosアプリから画像をアップロードしたときと同じ問題が発生しました。 マルチパートリクエストを提供してください。 私の場合は:(モデル)has_attached_file:avatar_defaultとOn ios app NSObject with attributs avatar_default_file_name | avatar_default_content | avatar_default_content_type –

関連する問題