无法从 facebook carrierwave 上传图片

Cant upload image from facebook carrierwave

我目前有一个用户配置文件,允许用户上传图像文件,使用 jQuery 获取裁剪数据,然后将其发送到 CarrierWave/RMagick 以获得 cropping/processing。它终于运作良好。

我现在 运行 遇到的问题是,如果用户使用 Facebook (oAuth) 注册,我想默认将他们的个人资料图片设置为他们的 Facebook 图片。我希望这是同一个字段 (TalentProfile.profile_image),因为我希望用户能够将其替换为自定义上传或根据需要将其删除。

这是我目前的流程:

这是我的 talent_profile.rb 模型:

class TalentProfile < ApplicationRecord
    belongs_to :user
    mount_uploader :profile_image, ProfileImageUploader
    validates :profile_image, file_size: { less_than: 5.megabytes }

    def crop_profile_image
        if crop_x.present?
            profile_image.recreate_versions!
        end
    end

    def self.set_facebook_image(profileId, auth)
        @profile = TalentProfile.find(profileId)
        @profile.profile_image = auth.info.image
        byebug
    end
end

当self.set_facebook_image 为运行 时,@profile.profile_image 似乎不能这样设置,除非我删除mount_uploader 并验证行。它总是以 nil 出现,即使 auth.info.image 是我需要的 URL。这让我相信,如果我更新 CarrierWave 就无法像这样处理它;似乎需要提交表单。

我怎样才能完成这项工作?可能吗?感谢您提供任何信息!

您应该使用 remote_profile_image_url 方法从远程 url 上传图片。