在rails中使用paperclip时获取全局s3存储桶名称

时间:2022-04-30 10:44:42

This is probably a silly question, but is there a way I can pull out the root bucket name out of the YML s3 file I have? Other tutorials I've seen just assume that the buckets are named development/test-(whatever). I just want to pull exactly what is in the amazon 3s yml out of there, or else I'll have to hard code it...

这可能是一个愚蠢的问题,但有没有办法可以从我拥有的YML s3文件中提取根桶名称?我见过的其他教程只是假设这些桶名为development / test-(无论如何)。我只是想把亚马逊3s yml里面的东西拉出来,否则我将不得不硬编码......

I've tried like S3_CONFIG['bucket_name'] but I think that may be attachment_fu specific, not sure.

我试过像S3_CONFIG ['bucket_name'],但我认为这可能是attachment_fu特定的,不确定。

1 个解决方案

#1


-1  

Remember, you can always parse the YAML file yourself.

请记住,您始终可以自己解析YAML文件。

Probably something along these lines:

可能是这些方面的东西:

config = YAML.load_file(Rails.root.join('config', 'aws_s3.yml'))
bucket_name = config[Rails.env]['bucket_name']

#1


-1  

Remember, you can always parse the YAML file yourself.

请记住,您始终可以自己解析YAML文件。

Probably something along these lines:

可能是这些方面的东西:

config = YAML.load_file(Rails.root.join('config', 'aws_s3.yml'))
bucket_name = config[Rails.env]['bucket_name']