载波+ json 响应中的 Mongoid 完整 url
我正在尝试为移动应用程序构建 api,并使用 Carrierwave 和 Mongoid。上传和检索图像一切正常,但是当我生成 json 响应时,图像 url 仅显示 path/to/image.png 而不是 http://localhost:3000/path/to/image.png。
如何让我的应用程序生成图像的完整 url。我在谷歌上进行了广泛的搜索,但无法找到任何可靠的解决方案。
预先感谢您的帮助。
I am trying to build an api for a mobile app and am using Carrierwave and Mongoid. Everything works fine with uploading and retrieving the images, but when i generate the json response the image urls simply show a path/to/image.png instead of http://localhost:3000/path/to/image.png.
How do I get my app to generate the full url to the image. I have done an extensive search on google but am unable to find any solid solutions.
Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为默认情况下你不能使用 Carrierwave 来做到这一点,但是你可以通过这个猴子补丁来解决这个问题,
因为你无法从上传者(任何模型)访问 Rails
session/request
信息,你需要定义application_controller
中的before_filter
来加载请求数据我仅在本地存储/mongoid 中测试了此补丁。我不知道这在亚马逊 s3/fog 中如何工作..
希望这有帮助
I dont think you can do this with carrierwave by default, but you can workaround this by this monkey patch
since you cannot access the rails
session/request
info from the uploader(any model), you need to define thebefore_filter
inapplication_controller
to load the request dataI have tested this patch only in local storage/mongoid. I dont know how this will work in amazon s3/fog..
Hope this helps