3

I am trying to upload image using grape api. I have done the following steps.

  1. rails active_storage:install
  2. rails g model user name email avatar:attachment
  3. rails db:migrate
module API
  module V1
    class Users < Grape::API
      include API::V1::Defaults
      desc 'Create User'
      params do
        requires :name, type: String, desc: "User name"
        requires :email, type: String, desc: "User email"
        requires :avatar, :type => Rack::Multipart::UploadedFile, :desc => "Image file."
      end
      put "/user" do
        binding.pry
        User.create(params)
        return {status: 'success'}
      end
    end
  end
end

But I am getting the following error,

ArgumentError: missing keyword: io
from /Users/nnnn/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activestorage-6.1.4/app/models/active_storage/blob.rb:97:in `build_after_unfurling'

Help me to fix this issue. curl command to hit the server.

[![curl --location --request PUT 'localhost:3000/api/v1/user' \ --header 'Cookie: __profilin=p%3Dt' \ --form 'avatar=@"/Users/nnnn/Downloads/1623340316453.jpeg"' \ --form 'name="Tester"' \ --form 'email="tester@gmail.com"'][1]][1]

enter image description here

Deepesh
  • 6,138
  • 1
  • 24
  • 41
sel
  • 169
  • 5
  • 13

0 Answers0