Active Storage 以如下文件结构存储上传:
Active Storage stores uploads in a file structure like so:
如果 rails 应用程序是唯一需要使用这些文件的软件,那就太好了.
This is great if the rails app is the only software that needs to use these files.
但是,如果应用程序只是将图像上传到 S3 以便其他(完全独立的)服务可以使用它们呢?
But what if the app simply serves as a means to upload the images to S3 so that some other (completely separate) service can consume them?
问题是,其他开发人员无法理解目录和文件,因为它们以 rails 可以理解的方式进行标记,但人类无法理解(例如,名为O2"的文件夹是什么?;是什么意思?).
The problem being, other developers wouldn't be able to make any sense of the directory and files, since they're labelled in a way rails can understand, but which a human cannot (e.g. what does folder named "O2" mean?).
有什么方法可以确保以人性化的方式存储上传的内容?例如每个文件夹都可以是一个 user_id,里面有他们的资产?(或类似)
Is there some way to ensure uploads are stored in a human-friendly way? e.g. each folder could be a user_id, with their assets inside? (or similar)
推荐答案据我所知,你必须实现一个自己的服务,以某种方式将 key 替换为其他东西(例如 S3Service),或将 ActiveStorage 修补到以不同的方式创建密钥本身.不过,我不确定这是否足够,因为密钥很可能用于服务之外的其他关键功能.
As far as I remember, you would have to implement an own service that somehow replace the key used to something else (e.g. S3Service), or patch ActiveStorage to create the key itself in a different way. I am not sure that this would suffice though, as the key is most likely used for other critical functionality outside of the Service.
或者,您可以查看 来处理 key.也就是说,ActiveStorage 不支持您开箱即用的功能,您将不得不冒弄乱其内部结构的风险.
Alternatively you might poke in ActiveStorage::Blob to fiddle with the key. That said, ActiveStorage does not support what you'd like out of the box and you would have to take the risk of messing with its internals.
问题的解决方案(但不能回答您的问题)可能是实施您问题的评论中概述的 API.
A solution to the problem (but not answer to you question) might be implementing an API as outlined in the comments to your question.
更多推荐
组织 Active Storage 文件以在其他系统中使用?
发布评论