用Paperclip获取服务器文件路径 [英] Get server file path with Paperclip

查看:154
本文介绍了用Paperclip获取服务器文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Paperclip来制作一个小文件上传应用程序。我希望能够返回上传文件的服务器上的文件路径一旦完成,但我似乎无法弄清楚如何获得路径?回形针只似乎记录文件本身的名称。



有人现在怎么做到这一点? 假设你在用户的实例上有一个名为avatar的附件,你可以使用 user.avatar.path 获得文件系统上文件的完整路径,你可以使用 user.avatar.url 给你可以在图片标签和whatnot中使用的路径。



这就是你'是什么意思?

I'm using Rails with Paperclip to make a small file upload app. I would like to be able to return the file path on the server of the uploaded file once its done but I can't seem to work out how to get the path? Paperclip only seems to record the name of the file itself.

Does anybody now how to do this?

解决方案

Assuming you had an attachment called avatar on an instance of a user, you can use user.avatar.path to get the full path of the file on the filesystem, and you can use user.avatar.url to give the path which you could use in image tags and whatnot.

Is that what you're meaning?

这篇关于用Paperclip获取服务器文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆