我正在使用ckeditor
,我将图片上传到我使用carrierwave
和minimagick
配置的Dropbox。几天后,虽然图片没有出现在博客文章中,但它在控制台中显示以下内容
Failed to load resource: the server responded with a status of 401 (Not Authorized)
示例链接(资源图像)
https://dl.dropboxusercontent.com/1/view/5qo62va4g4uwsqn/uploads/ckeditor/pictures/1/content_1.png
如果我转到ckeditor并再次浏览图像并重新加载它,它会工作几天然后相同。
有什么我想念的吗?
答案 0 :(得分:1)
由于carrierwave-dropbox
gem使用API的media
部分和greg,如评论中所指出的,此链接会在几个小时后过期。
这是我使用shares
首先找到carrierwave-dropbox gem
安装位置导航到
lib\carrierwave\storage\dropbox.rb
并将行54
更改为以下
@client.shares(@path, short_url = false)["url"]
接下来在application_helper.rb
def rewrite_url(url)
u = url
u.slice! "dl=0"
u = u + "raw=1"
u
end
基本上所做的就是从返回的字符串中删除dl = 0部分,因为它指向在dropbox上预览并在末尾添加raw=1
以实际显示直接文件。
接下来,在图片标记
上调用它 <%= image_tag rewrite_url(@question.image_url(:resized)) %>
:resized
是因为我调整了图像的大小,关键部分是将图片网址包装到帮助器中
read_more:more info
非常感谢 Greg 的帮助。