简体   繁体   English

使用Paperclip将图像从数据库下载到项目文件夹

[英]Download image from database to project folder with Paperclip

I want to download an image stored in database with paperclip and put it in my project folder. 我想用回形针下载存储在数据库中的图像并将其放在我的项目文件夹中。 In app/assets/images for example. 例如在应用程序/资产/图像中。

Why? 为什么? : Because I want to put image in a Word. :因为我想在Word中放入图像。 So when I use docx_replace or caracal gem I cant put directly image within the variable from database (that don't work). 因此,当我使用docx_replacecaracal gem时,我无法直接将图像放在数据库变量中(不起作用)。 But I can put image directly from folder. 但是我可以直接从文件夹放图像。 So I want to put the image from DB to folder, put in the Word and delete it after insertion. 因此,我想将图像从数据库放到文件夹中,放入Word中,并在插入后将其删除。 That's why. 这就是为什么。 But if you have another technique tell me. 但是,如果您还有其他技巧,请告诉我。

Do you now a way in order to do that ? 您现在是否有办法做到这一点?

As you store your files locally and paperclip provides helpers to the full path of the file, you can just use Ruby FileUtils to copy the file to the public directory in your action. 当您将文件存储在本地并且回形针为文件的完整路径提供帮助时,您只需在操作中使用Ruby FileUtils将文件复制到public目录即可。 You don't need to download it, because it is already in the filesystem. 您不需要下载它,因为它已经在文件系统中。
This answer provides some base code for this: https://stackoverflow.com/a/5776577/1023609 此答案为此提供了一些基本代码: https : //stackoverflow.com/a/5776577/1023609

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

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