我正在尝试创建一个应用程序,用户可以上传,下载和流式传输音乐到Amazon Web Services,简单存储服务(AWS-S3)。
我试图解决的一个问题是,当我尝试上传MP3文件时,我在终端中收到一个警告,在我被重定向之前重复四次,并向用户发出警告"无法" 39;完成上传"。我得到了##;摘要::摘要已被弃用;使用摘要"我在上传方法中的AWS对象上使用.store方法时发出警告。
还有其他人处理过这种情况并且可以帮助我吗?非常感谢,非常感谢。
这是我的控制者:
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
这是我尝试上传文件时终端中发生的事情:
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)
答案 0 :(得分:2)
您是否尝试过确保拥有最新版本的宝石?
检查你的gemfile:
gem "aws-sdk", "~> 1.33.0"
答案 1 :(得分:2)
阅读文档后,我设法找到,由AWS提供,我找到了调用我的AWS-S3对象AWS::S3::S3Object
的正确方法。 Here,它声明我必须在AWS::S3::S3Object
上使用.write方法。
在文档之后,我的问题已经解决,我再也没有收到重复的Digest::Digest is deprecated; use Digest
警告。
答案 2 :(得分:0)
我通过在application.rb中添加AWS :: S3 :: DEFAULT_HOST.replace('s3-us-west-2.amazonaws.com')解决了这个问题。在我的情况下,桶的区域是俄勒冈州,端点是's3-us-west-2.amazonaws.com'Regions and Endpoints