I tried to upload movie files from my rails application to Amazon S3. First I tried paperclip, but it dosn't worked ...
No I tried carrierwave + fog but same result nothing worked, no files stored in S3 no database entry and no errors ...
My Files look like this:
app/uploader/movie_uploader.rb
class MovieUploader < CarrierWave::Uploader::Base
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: '--',
aws_secret_access_key: '--',
region: 'eu-central-1'
}
config.fog_directory = 'movies'
end
app/models/movie.rb
class Movie < ActiveRecord::Base
mount_uploader :movie, MovieUploader
end
app/controller/movies_controller.rb
class MoviesController < ActionController::Base
layout "application"
# Method to add a new Movie
def addMovie
if request.post?
@movie = Movie.new(movies_params)
if @movie.save
redirect_to :addMovie
end
else
@movie = Movie.new
end
end
private
def movies_params
params.require(:movie).permit(:movietitle, :movieprice, :locked, :moviedescription, :currency, :language, :movie)
end
end
upload form
normal multipart form_tag
<%= form_for Movie.new, :html => {:multipart => true, :class => "form-horizontal", :role => "form"}, :method => :post, :url => {} do |f| %>
with file field
<div class="form-group">
<label><%= f.label :movie %></label>
<%= f.file_field :movie, :class => "form-control", :placeholder => :movie %>
</div>
I used this tutorial: https://u.osu.edu/hasnan.1/2014/03/13/rails-4-upload-image-to-s3-using-fog-and-carrierwave/
Whats going wrong?