[英]How can i retrieve uploaded image (base64) full url from Carrierwave upload file to Rackspace?
我只需要獲取剛剛通過Carrierwave上傳到Rackspace服務器的圖像(base64)的URL。
現在是我的控制器。
def update_with_image
user = current_user
uploader = PictureUploader.new
uploader.store!(user_update_params[:profile_image]) // base64 image like this 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2w...'
// How can i update user_update_params[:profile_image] with the successfully uploaded profile_image url?
if user.update_attributes(user_update_params)
# Handle a successful update.
render json: user, status: 200 ,serializer: UserSerializer
else
render json: { errors: user.errors }, status: 422
end
end
那么在uploader.store!(user_update_params[:profile_image])
,我如何獲取該文件的URL?
謝謝!
你是這個意思 ?
uploader = AvatarUploader.new
uploader.store!(my_file) # size: 1024x768
uploader.url # => '/url/to/my_file.png' # size: 800x600
uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
在上傳器上調用url
方法應該可以獲取URL。 的github
更新:引用載波GitHub
您可以選擇在配置中包括CDN主機名。 強烈建議這樣做,因為沒有它,每個請求都需要查找此信息。
config.asset_host = "http://c000000.cdn.rackspacecloud.com"
在您的上傳器中,將存儲設置為:fog
class AvatarUploader < CarrierWave::Uploader::Base
storage :fog
end
而已! 您仍然可以使用CarrierWave::Uploader#url
方法將URL返回到Rackspace Cloud Files上的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.