Я пытаюсь загрузить изображение профиля пользователя из моего приложения в централизованное приложение с использованием оператора carrierwave. В параметрах аватар пропускается, но не обновляется.
Вот мой журнал заявок:
Started PATCH "/api/v1/users/47" for ::1 at 2018-07-01 13:45:14 +0530
Processing by Api::V1::UsersController#update as JSON
Parameters: {"user"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x00007f7c7cda6e20 @tempfile=#<Tempfile:/tmp/RackMultipart20180701-10347-otl55f.jpg>, @original_filename="leotolstoy1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"leotolstoy1.jpg\"\r\nContent-Type: image/jpeg\r\n">, "first_name"=>"Mayuresh"}, "id"=>"47"}
И централизованный журнал приложений:
Started POST "/api/v1/users/update" for 127.0.0.1 at 2018-07-01 13:45:15 +0530
Processing by Api::V1::UsersController#update as */*
Parameters: {"first_name"=>"Mayuresh", "last_name"=>nil, "avatar"=>{"tempfile"=>"#<File:0x00007f7c7c6ba468>", "original_filename"=>"leotolstoy1.jpg", "content_type"=>"image/jpeg", "headers"=>"Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"leotolstoy1.jpg\"\r\nContent-Type: image/jpeg\r\n"}, "user"=>{"first_name"=>"Mayuresh", "last_name"=>nil, "avatar"=>{"tempfile"=>"#<File:0x00007f7c7c6ba468>", "original_filename"=>"leotolstoy1.jpg", "content_type"=>"image/jpeg", "headers"=>"Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"leotolstoy1.jpg\"\r\nContent-Type: image/jpeg\r\n"}}}
Application Load (0.4ms) SELECT "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."secret" = $1 ORDER BY "oauth_applications"."id" ASC LIMIT $2 [["secret", "<secret_token>"], ["LIMIT", 1]]
AccessToken Load (0.4ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."active" = $1 AND "oauth_access_tokens"."token" = $2 ORDER BY "oauth_access_tokens"."id" ASC LIMIT $3 [["active", true], ["token", "<access_token>"], ["LIMIT", 1]]
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
(1.8ms) BEGIN
User Exists (1.5ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 AND ("users"."id" != $2) AND "users"."type" = $3 LIMIT $4 [["email", "<email>"], ["id", 1], ["type", "User"], ["LIMIT", 1]]
SQL (0.4ms) UPDATE "users" SET "first_name" = $1, "updated_at" = $2 WHERE "users"."id" = $3 [["first_name", "Mayuresh"], ["updated_at", 2018-07-01 08:15:15 UTC], ["id", 1]]
(12.7ms) COMMIT
Как видите, обновляется только имя, а не аватар.
Загрузка аватара в централизованном приложении:
class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
'tmp/upload/'
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url(*args)
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process scale: [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process resize_to_fit: [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_whitelist
%w(jpg jpeg png)
end
def content_type_whitelist
/image\//
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
Даже если я пытаюсь обновить консоль rails в централизованном приложении, оно не обновляется.
2.3.4 :049 > user.update avatar: 'https://static1.squarespace.com/static/586af0132994caa37cca0067/5876e27f9f74561d8c5ce4df/5876e296c534a514869fe56e/1484187414154/Tree+On+The+Bank.jpg'
(0.7ms) BEGIN
User Exists (0.8ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 AND ("users"."id" != $2) AND "users"."type" = $3 LIMIT $4 [["email", "<email>"], ["id", 1], ["type", "User"], ["LIMIT", 1]]
SQL (0.4ms) UPDATE "users" SET "updated_at" = $1, "avatar" = $2 WHERE "users"."id" = $3 [["updated_at", 2018-07-01 07:39:16 UTC], ["avatar", "abc.jpg"], ["id", 1]]
(13.4ms) COMMIT
=> true
Не в состоянии понять, что здесь не так.