使用回形针 +赫罗库 + s3 ...本地上传在推送时损坏

发布于 2024-11-26 13:03:31 字数 683 浏览 0 评论 0原文

我正在建立一个小型网站,其中有相当多的图片>当地一小群人 100 人。如果我通过本地计算机上的回形针将文件上传到 s3,它们工作得很好,但是当我将其推送到 heroku 时,这些图片就会损坏(又名指向错误的位置)。

如果我从heroku中提取实时数据库(我将照片上传到在线应用程序,然后提取在线数据库的情况)。这些图像不会加载到我的本地应用程序中。

关于如何让它发挥作用有什么想法吗?

编辑: 对这个问题的更多澄清:我现在已经在模型中设置了路径,如下所示

:path => "/public/system/:attachment/:style/:id.:extension"

,它现在控制访问 S3 时 url 的外观。然而,我的本地计算机将其输出为图像源:

bucket/Users/msencenb/Development/appname/public/system/pictures/7/thumb/overlook.jpg?2011

而heroku应用程序源看起来像这样:

bucket/app/public/system/pictures/7/thumb/overlook.jpg?2011

如您所见,这非常相似,除了本地计算机也将目录结构注入源路径中。如何用回形针找到源路径?

I am building a small website that has a fairly large amount of pictures > 100 for a small local group of people. If I upload files to s3 via paperclip on my local machine they work just fine, but when I push it to heroku those pics are then broken (aka pointing to the wrong location).

If I pull the live database from heroku (case where I upload photos to the app that is online, then pull the online database). Those images don't load in my local app.

Any ideas on how to get this working?

EDIT:
Some more clarification on the problem: I have now set the path within the model like so

:path => "/public/system/:attachment/:style/:id.:extension"

And it now controls how the url looks when accessing S3. However my local machine outputs this as the image source:

bucket/Users/msencenb/Development/appname/public/system/pictures/7/thumb/overlook.jpg?2011

while the heroku app source looks like this:

bucket/app/public/system/pictures/7/thumb/overlook.jpg?2011

As you can see this is very similar except the local one injects the directory structure into the source path as well. How can I the source path with paperclip?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剩一世无双 2024-12-03 13:03:31

请参阅此博文:

http://codeglot.com/posts/68-upoading_pictures_to_apps_on_heroku

我已经有多个使用回形针和 s3 的应用程序。我的设置方式如下:

  has_attached_file :picture, 
                     :styles => {:large => "275x450>"},
                     :storage => :s3, 
                     :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                     :path => "appname/:attachment/:style/:id.:extension"

确保将 appname 替换为应用程序的名称。例如您可以在 heroku 上访问您的应用程序的子域。

See this blog post:

http://codeglot.com/posts/68-upoading_pictures_to_apps_on_heroku

I've have multiple apps that use paperclip and s3. This is how I have it setup:

  has_attached_file :picture, 
                     :styles => {:large => "275x450>"},
                     :storage => :s3, 
                     :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                     :path => "appname/:attachment/:style/:id.:extension"

Make sure you replace your appname with the name of your app. such as the subdomain you can access your app on heroku.

執念 2024-12-03 13:03:31

当您在本地计算机上工作时,文件将使用本地数据库中的 id 上传到 S3,当您推送到 heroku 时,如果您不使用本地内容更新远程数据库,引用将被破坏。

When you work on your local machine, the files are uploaded to S3 using the ids from your local database, and when you push to heroku, if you don't update the remote database with your local content, the references will be broken.

墨小墨 2024-12-03 13:03:31

尝试去掉路径开头的正斜杠。

:path => "public/system/:attachment/:style/:id.:extension"

它不应该像这样采用应用程序路径(本地上的 Users/msencenb/Development/appname 和 Heroku 上的应用程序)。某些原因导致了这种情况,如果去掉斜线不起作用,那么尝试调查其他原因会导致这种情况。

Try taking out the forward slash you have at the beginning of your path.

:path => "public/system/:attachment/:style/:id.:extension"

It shouldn't be taking the app path (Users/msencenb/Development/appname on local and app on Heroku) like that. Something is causing it and if taking the slash out doesnt work then try to investigate what else would be causing this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文