I'm trying to get refinerycms to upload files to s3, using the fog gem.
I'd like to pull my S3 credentials from a file that is not in my git repo (e.g. s3.yml)
I found some old references to doing this using the aws-s3 gem, but not fog.
Thanks in advance for any help!
I keep my config in a config file rather than a yml file.
In config/s3_config.rb:
ENV['S3_KEY'] = 'MYS3KEY'
ENV['S3_SECRET'] = 'MYSECRETKEY'
ENV['S3_BUCKET'] = 'this-is-my-bucket'
When you run your rails app (this would be in development), the config file is automatically loaded, so those credentials will be referenced to the constants (ENV['S3_KEY']).
This would be different when you deploy your application. For instance Heroku, you would create those config vars.
Related
Im using Settingslogic gem as alternative to Environment Variables, and I found it more convenient. But, how to deploy the application to Heroku if my file with configs is out of the repo? I mean, all configs I save in application.yml, which is included in .gitignore file (because there is sensitive data). And when I push it to heroku, server can't find this file and can't complete deploy.
I've tried to create the file from heroku bash, but after git push heroku master command, created file disappears, and deploy failes with the same error.
How can I implement this deploy with one config file, and how can I force heroku to read this file or store it if I have no it in Git? Thanks a lot!
I am having a hard time getting s3 images to show in deployment. I have 2 buckets on aws s3, one for dev and for production.
only the production bucket get filled up with images when I run the code below for my images. (You can see this on the images I attached) I also dont get any errors on chrome console.
Restaurant.last.main_photo.attach(io: File.open("/home/vault/Desktop/halal-table-photos/profile-photos/blur-breakfast-chef-cooking-262978.jpg"), filename: "23.jpg")
I've tried the Open-uri gem
require 'open-uri'
Restaurant.last.main_photo.attach(io: open("/home/vault/Desktop/halal-table-photos/profile-photos/blur-breakfast-chef-cooking-262978.jpg"), filename: "23.jpg")
Here are my s3 setups
https://github.com/MahmudAhmed/HalalTable <- git repo
https://halal-table.herokuapp.com/#/restaurants
https://halal-table.herokuapp.com/
I examine your project from Github. There is no visible problem on the code, but only thing I didn't see here is your Heroku config. You need to either say Heroku to use specific bucket for production via heroku config vars or initialize config/initializers/aws.rb and say heroku to use different bucket in production. In here you can get really got information about s3 buckets in Rails with different environments in action.
In my rails 3 app I'm generating a file when a user does an action. This file needs to be permanent. So this file needs to be stored in some place like S3 AWS. What is the simplest way to do this using S3 AWS (aws-sdk v1)?
The image its genererated using the gem barby (https://github.com/toretore/barby), so the user doesn't need to upload it.
Use the AWS SDK for Ruby to copy the file to S3. The official documentation pretty much gives you the code:
require 'aws-sdk'
s3 = Aws::S3::Resource.new(region:'us-west-2')
obj = s3.bucket('bucket-name').object('key')
obj.upload_file('/path/to/source/file')
Correct Mark B! This is with the version AWS SDK version 2.
Witht the version 1 its:
require 'aws-sdk'
s3 = AWS::S3.new
# Upload a file.
key = File.basename(file_name)
s3.buckets[bucket_name].objects[key].write(:file => file_name)
I'm using AssetSync to sync to an S3 bucket. It seems to work fine. However, I'd like to be able to add versioning to the S3 bucket. So instead of just the bucket name, I want to put the deployed assets into a subdirectory like
my-bucket/v1/
I tried adding the 'v1' folder to the FOG_DIRECTORY env var, but that doesn't seem to be the thing to do. Is there an easy way to specify a subdir of a bucket?
Found the answer myself. Thanks for nothin'.
AssetSync.config.assets.prefix
I am trying to deploy a rails app to heroku, and I know that their file system is read only, and it only contains the latest code. I am using a git repository, via this guide. I have a config file, holding passwords and other stuff that I don't want to track on git, but I have to upload them to heroku. How can I accomplish that?
Rather than store the confidential info in the app files, set them up as environment variables on heroku using config vars
Ref: https://stackoverflow.com/a/7832040/429758