使用 Carrierwave 保存文件,无需表单
我有 2 个模型 - 专辑和专辑图像。
每个相册都有与其关联的相册图像,并且它们是使用 Carrierwave 通过 AlbumImageUploader 类上传的。
现在我想使用现有的关联专辑图像为每个专辑选择专辑封面。在将其用作专辑封面之前,我需要处理(裁剪和调整大小)此选定的图像。我已经实现了裁剪和调整大小功能,并且创建了一个 AlbumCoverUploader 类来保存专辑图像的处理版本。
问题是,这次我没有使用表单上传新的图像文件,而是使用文件系统中现有的相册图像,并且我不确定如何将此图像从我的AlbumImageUploader 类传输到我的AlbumCoverUploader 类。
有什么想法吗?
I have 2 models - Album and AlbumImage.
Each album has album images associated with them, and they are uploaded via the AlbumImageUploader class using Carrierwave.
Now I want to select an album cover for each album using the existing associated album images. I need to process (crop and resize) this selected image before I use it as the album cover. I have the cropping and the resizing functions down, and i created an AlbumCoverUploader class to save this processed version of the album image to.
The problem is that this time I am not using a form to upload a new image file and instead using an existing album image in the file system, and I'm not sure how to transfer this image from my AlbumImageUploader class to my AlbumCoverUploader class.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这真的很简单。
您必须像从表单上传一样配置您的AlbumCoverUploader。
不过,要使用与现有记录关联的图像,您必须执行以下操作:
这将抓取图像文件并用作 AlbumCoverUploader 的输入来创建自己的图像副本。
This is really simple.
You have to configure your AlbumCoverUploader the same way as if you would upload it from a form.
Though, to use an image which is associated with an existing record, you must do the following:
This will grab the image file and use as an input for the AlbumCoverUploader to create its own copy of the image.