I am trying to create an application in which a user can upload, download and transfer music to Amazon Web Services, Simple Storage Services (AWS-S3).
The problem I'm trying to solve is when I try to download an MP3 file, I get a warning in my terminal that repeats exactly four times before I am redirected and warned with my message to the user. "Failed to complete the download." I get a "Digest Digest" warning, I do not recommend using digest when I use the .store method on my AWS object in the upload method.
Has anyone else dealt with this situation and can help me? Thank you very much.
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 happens in my terminal when I try to upload a file:
taimurs-mbp:batana taimurknaziri$ rails s
=> Booting WEBrick
=> Rails 4.1.4 application starting in development on http:
=> 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
Started POST "/songs/upload" for 127.0.0.1 at 2014-08-19 12:19:26 -0400
Processing by SongsController
Parameters: {"utf8"=>"✓", "authenticity_token"=>"/ZUu7QCsH9D1DYVpXoFkXaOnghbgjm7J/fkJ6zAAmgs=", "mp3file"=>
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)
source
share