I am attempting to make an app where a user can upload, download and stream music to Amazon Web Services, Simple Storage Services (AWS-S3).
An issue I am trying to resolve is when I attempt to upload an MP3 file I receive a warning in my terminal that repeats itself exactly four times before I get redirected and alerted with my message to the user "Couldn't complete the upload". I get the "Digest::Digest is deprecated; use Digest" warning when I use the .store method on my AWS object in the upload method.
Has anyone else dealt with this situation and can possibly help me out? Thank you so much it is greatly appreciated.
This is my controller:
class SongsController < ApplicationController
BUCKET = 'batana_application'
def index
@songs = AWS::S3::Bucket.find(BUCKET).objects
end
def upload
begin
AWS::S3::S3Object.store(sanitize_filename(params[:mp3file].original_filename), params[:mp3file].read, BUCKET, :access => :public_read)
redirect_to root_path
rescue
render :text => "Couldn't complete the upload"
end
end
def delete
if (params[:song])
AWS::S3::S3Object.find(params[:song], BUCKET).delete
redirect_to root_path
else
render :text => "No song was found to delete!"
end
end
private
def sanitize_filename(file_name)
just_filename = File.basename(file_name)
just_filename.sub(/[^\w\.\-]/,'_')
end
end
and this is what is going on in my terminal when I attempt to upload a file:
taimurs-mbp:batana taimurknaziri$ rails s
=> Booting WEBrick
=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-08-19 12:19:18] INFO WEBrick 1.3.1
[2014-08-19 12:19:18] INFO ruby 2.1.1 (2014-02-24) [x86_64-darwin12.0]
[2014-08-19 12:19:18] INFO WEBrick::HTTPServer#start: pid=4469 port=3000
Started POST "/songs/upload" for 127.0.0.1 at 2014-08-19 12:19:26 -0400
Processing by SongsController#upload as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"/ZUu7QCsH9D1DYVpXoFkXaOnghbgjm7J/fkJ6zAAmgs=", "mp3file"=>#<ActionDispatch::Http::UploadedFile:0x00000104eaa128 @tempfile=#<Tempfile:/var/folders/l7/f3_r_hhs46lfprth_1pw57vw0000gn/T/RackMultipart20140819-4469-1dw6jsw>, @original_filename="doubletrouble.mp3", @content_type="audio/mp3", @headers="Content-Disposition: form-data; name=\"mp3file\"; filename=\"doubletrouble.mp3\"\r\nContent-Type: audio/mp3\r\n">, "commit"=>"Upload"}
Digest::Digest is deprecated; use Digest
Digest::Digest is deprecated; use Digest
Digest::Digest is deprecated; use Digest
Digest::Digest is deprecated; use Digest
Rendered text template (0.0ms)
Completed 200 OK in 31895ms (Views: 5.8ms | ActiveRecord: 0.0ms)