curlコマンドでS3に画像をアップロードしたいです。
その場合curlコマンドはどのように指定してあげれば良いのか分からずにいます。
テストしたcurlコマンド
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST -d '{"user" : {"image" : "@test.jpg"}}' http://localhost:3000/api/v1/users.json
jsonのurlを叩いて、urlの欄にS3のURLが見えることがゴールなのですが、表示されません。
使用しているフレームワークはRailsで、carrierwaveというgemを使用しています。
以下のコードでローカルにpostされた画像をS3に指定しています。
参考リンク
initializers/carrierwave.rb
CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS', :aws_access_key_id => ENV['AWS_ACCESS_KEY'], :aws_secret_access_key => ENV['AWS_SECRET_KEY'], :region => s3-ap-northeast-1, :path_style => true } config.fog_public = true config.fog_attributes = {'Cache-Control' => 'public, max-age=86400'} case Rails.env when 'production' config.fog_directory = 'bucket' config.asset_host = 'http://s3-ap-northeast-1.amazonaws.com/buket' when 'development' config.fog_directory = 'bucket-dev' config.asset_host = 'http://s3-ap-northeast-1.amazonaws.com/bucket-dev' end end
api/v1/users_controller.rb
class Api::V1::UsersController < ApplicationController def index @users = User.all end def create @user = User.new(user_params) respond_to do |format| if @user.save format.json { render json: 'good', status: :created } else format.json { render json: 'bad', status: :unprocessable_entity } end end end def user_params params.require(:user).permit(:image) end end
Railsアプリにアップロードした画像をS3に保存(さらにcurlで動作テスト)したいです。
画像をcurlで送信、JSONフォーマットで受け取り、AWSへデータが飛んでいるかが不明確のままでいます。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。