4

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)
illywilly
  • 323
  • 1
  • 5
  • 18

3 Answers3

2

Have you tried making sure you have a current version of the gem?

Check your gemfile:

gem "aws-sdk", "~> 1.33.0"
emcanes
  • 1,398
  • 10
  • 7
  • Hey @emcanes thanks for your response. I tried what you suggested however that seem to have stopped my app from working. What I have in there right now is: gem 'aws-s3', :require => 'aws/s3' ...Also I read some documentation and called the method '.write' on my S3 Object instead of '.store', that solved the issue of getting rid of the Digest::Digest is deprecated; use Digest warning, however now, I immediately get redirected and alerted that the file cannot be uploaded. – illywilly Aug 20 '14 at 14:53
2

After reading documentation I managed to find, provided by AWS I found out the proper method to call on my AWS-S3 Object AWS::S3::S3Object. Here, it state's that I must use the .write method on my AWS::S3::S3Object.

Following the documentation my problem was solved and I was not receiving the repeated Digest::Digest is deprecated; use Digest warning anymore.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
illywilly
  • 323
  • 1
  • 5
  • 18
  • I have the problem and I'm using the 'write' method. Upgrading the aws-sdk gem from 1.6.3 to 1.33.0 solved it for me. – jerryb Aug 09 '16 at 06:03
0

I solved this issue by adding AWS::S3::DEFAULT_HOST.replace('s3-us-west-2.amazonaws.com') in application.rb. In my case region of bucket is Oregon and endpoint is 's3-us-west-2.amazonaws.com' Regions and Endpoints

Sasha Stadnik
  • 502
  • 1
  • 6
  • 16