Organise Active Storage files for use in other systems?

感情迁移 提交于 2021-02-17 05:58:04

问题


Active Storage stores uploads in a file structure like so:

This is great if the rails app is the only software that needs to use these files.

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?

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?).

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)


回答1:


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.

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.

A solution to the problem (but not answer to you question) might be implementing an API as outlined in the comments to your question.



来源:https://stackoverflow.com/questions/64132729/organise-active-storage-files-for-use-in-other-systems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!