[英]How to replace uploaded image with Phoenix and Arc?
I use Arc to upload images - it's basic structure of uploader - I don't do any custom or fancy actions there - validate, transform or filename are all similar to the ones in example . 我使用Arc上传图像-这是上传器的基本结构-我在那里不执行任何自定义或奇特的操作-验证,转换或文件名都与示例中的相似。
I want to replace my uploaded image and as I see in uploads
folder, where I store them- everything is fine, but in my app as I check want to use url/2
like this: 我想替换上传的图片,并在
uploads
文件夹中看到存储位置,一切正常,但是在我的应用中,因为我检查要使用url/2
如下所示:
Avatar.url({file, scope}, :thumb)
it returns me url to the old file and sometimes this old file is broken- rendered only partially. 它将我的url返回到旧文件,有时这个旧文件只被部分渲染。 Using
mix phoenix.server
doesn't change the situation. 使用
mix phoenix.server
不会改变这种情况。 Is there any weird cache? 有任何奇怪的缓存吗? I could use nasty work-around to ensure that file
thumb.png
is deleted, whenever it exists, but is there any different way? 我可以使用讨厌的解决方法来确保在文件
thumb.png
存在时将其删除,但是还有其他方法吗?
TL;DR : How to replace the uploaded image with the same name to make sure that new usage of url
(provided by Arc.Storage.Local or Arc.Storage.S3) will work properly? TL; DR :如何用相同的名称替换上载的图像,以确保新使用的
url
(由Arc.Storage.Local或Arc.Storage.S3提供)可以正常工作?
The easiest work around in this case for me was to name differently each new uploaded image. 对于我来说,最简单的解决方法是为每个新上传的图像命名不同。 To do so I used additional field in schema which holds the
logo_number
(I didn't wanted to name it id) and ensure that all of old files are deleted with simple usage of File
module functions - namely ls
and rm!
为此,我在架构中使用了其他字段,该字段中包含
logo_number
(我不想将其命名为id),并确保通过使用File
模块功能(即ls
和rm!
简单地删除所有旧文件rm!
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.