简体   繁体   English

回形针:从文件系统存储迁移到Amazon S3

[英]Paperclip: migrating from file system storage to Amazon S3

I have a RoR website, where users can upload photos. 我有一个RoR网站,用户可以在其中上传照片。 I use paperclip gem to upload the photos and store them on the server as files. 我使用回形针gem上载照片并将它们作为文件存储在服务器上。 I am planning to move to Amazon S3 for storing the photos. 我打算搬到Amazon S3来存储照片。 I need to move all my existing photos from server to Amazon S3. 我需要将所有现有照片从服务器移至Amazon S3。 Can someone tell me the best way for moving the photos. 有人可以告诉我移动照片的最佳方法。 Thanks ! 谢谢 !

You'll want to log into your AWS Console and create a bucket structure to facilitate your images. 您将要登录到AWS控制台并创建存储桶结构以简化映像。 Neither S3 nor Paperclip have any tools in the way of bulk migrations from file system -> s3, you'll need to use the tool s3cmd for that. 从文件系统-> s3进行批量迁移时,S3和Paperclip都没有任何工具,您需要为此使用s3cmd工具。 In particular, you're interested in the s3cmd sync command, something along the lines of: 特别是,您对s3cmd sync命令很感兴趣,类似于以下内容:

s3cmd sync ./public/system/images/ s3://imagesbucket

If you have any image urls hard-coded into your database (a la markdown/template code) this might be a little tricky. 如果您将任何图片网址硬编码到数据库中(la markdown /模板代码),这可能会有些棘手。 One option would be to manually update your urls to point to the new bucket. 一种选择是手动更新您的网址以指向新存储桶。 Alternatively, you can rack-rewrite . 或者,您可以进行机架重写

You can easily do this by creating a bucket on Amazon S3 that has the same folder structure as your public directory on your Rails app. 您可以通过在Amazon S3上创建一个存储桶来轻松地做到这一点,该存储桶具有与Rails应用程序中的public目录相同的文件夹结构。

So say for instance, you create a new bucket on Amazon S3 called MyBucket and it has a folder in it called images . 举例来说,假设您在Amazon S3上创建了一个名为MyBucket的新存储桶,该存储桶中有一个名为images的文件夹。 You'd just move all of your images within your Rails app's images folder over to that new bucket's images folder. 您只需将Rails应用程序的images文件夹中的所有images移到该新存储桶的images文件夹中即可。

Then you can set up your app to use an asset host like this answer describes: is it good to use S3 for Rails "public/images" and there an easy way to do it? 然后,您可以将您的应用设置为使用资产主机,如以下答案所述: 将S3用于Rails的“公共/图像”是否很好,并且有简单的方法吗?

If you are using image_tag or other tag helpers (javascripts, stylesheets, etc), then it will use that asset_host for production environments and properly generate the URL to your S3 bucket. 如果您使用image_tag或其他标签帮助程序(javascript,样式表等),则它将在生产环境中使用该asset_host并正确生成S3存储桶的URL。

I found this script which takes care of moving the images to Amazon S3 bucket using rake task. 我发现此脚本负责使用rake任务将图像移至Amazon S3存储桶。 https://gist.github.com/924617 https://gist.github.com/924617

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM