mercredi 14 janvier 2015

Amazon S3 upload issues with Ruby on Rails using Carrierwave

I can't figure out what I am doing wrong to upload my file to s3 using carrierwave. I am able to store files locally using only ruby but I need to use carrierwave to store them to s3. I am getting an error I believe deals with setting the correct aws information but I did that. I lack a lot of knowledge as I am just a beginner with ruby on rails. I want to directly upload files to a s3 bucket which I think I have configured with CarrierWave. Any help would be greatly appreciated. Thank you in advanced


View:



%div
%h3 Import a CSV File
= form_tag import_orders_path, :class => 'order-uploads', multipart: true do
= file_field_tag 'upload[file]'
/ :file for just getting param[:file] from server
%br
= submit_tag "Import CSV", :class => 'submit-file'


Initializer file(I added this manually so maybe this is a problem?)


carrierwave.rb



require 'fog'
require 'carrierwave'

CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'my_key_id', # required
:aws_secret_access_key => 'secret_access_key', # required
:region => 'us-east-1', # optional, defaults to 'us-east-1'
}
config.fog_directory = 'my_bucket' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>"max-age=#{365.day.to_i}"} # optional, defaults to {}
end


What I am trying but it fails:



uploader = AvatarUploader.new
uploader.store!(param[:upload][:file])


Error I get:



Completed 500 Internal Server Error in 5362ms
Completed 500 Internal Server Error in 5362ms
** [Airbrake] Notice was not sent due to configuration:
Environment Monitored? false
API key set? false
** [Airbrake] Notice was not sent due to configuration:
Environment Monitored? false
API key set? false

NameError (undefined local variable or method `path' for #<OrdersController:0x00000007637ea8>):
app/controllers/orders_controller.rb:14:in `import'



NameError (undefined local variable or method `path' for #<OrdersController:0x00000007637ea8>):
app/controllers/orders_controller.rb:14:in `import'


Rendered /http://ift.tt/1IynKRa (0.7ms)
Rendered /http://ift.tt/1IynKRa (0.7ms)
Rendered /http://ift.tt/1IynIZw (1.4ms)
Rendered /http://ift.tt/1IynIZw (1.4ms)
Rendered /http://ift.tt/1szI2G4 (0.9ms)
Rendered /http://ift.tt/1szI2G4 (0.9ms)
Rendered /http://ift.tt/1IynKRd (892.2ms)
Rendered /http://ift.tt/1IynKRd (892.2ms)


This works for local storage:



name = params[:upload][:file].original_filename
directory = "public/files"
path = File.join(directory, name)
File.open(path, "wb") { |f| f.write(params[:upload][:file].read) }
flash[:notice] = "File uploaded"




Aucun commentaire:

Enregistrer un commentaire