[英]How can i retrieve uploaded image (base64) full url from Carrierwave upload file to Rackspace?
I just need to get the url of my image (base64) that just uploaded to Rackspace server via Carrierwave. 我只需要获取刚刚通过Carrierwave上传到Rackspace服务器的图像(base64)的URL。
This is my controller now. 现在是我的控制器。
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
So after uploader.store!(user_update_params[:profile_image])
how can i get the url of that file? 那么在
uploader.store!(user_update_params[:profile_image])
,我如何获取该文件的URL?
Thanks! 谢谢!
You mean this ? 你是这个意思 ?
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
calling url
method on the uploader should get you the URL. 在上传器上调用
url
方法应该可以获取URL。 github 的github
Update: Quoting from carrier wave GitHub 更新:引用载波GitHub
You can optionally include your CDN host name in the configuration. 您可以选择在配置中包括CDN主机名。 This is highly recommended, as without it every request requires a lookup of this information.
强烈建议这样做,因为没有它,每个请求都需要查找此信息。
config.asset_host = "http://c000000.cdn.rackspacecloud.com"
In your uploader, set the storage to :fog 在您的上传器中,将存储设置为:fog
class AvatarUploader < CarrierWave::Uploader::Base
storage :fog
end
That's it! 而已! You can still use the
CarrierWave::Uploader#url
method to return the url to the file on Rackspace Cloud Files. 您仍然可以使用
CarrierWave::Uploader#url
方法将URL返回到Rackspace Cloud Files上的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.