Ruby on rails Rails应用程序,尝试从Amazon Web服务下载文件时出错
因此,我下面将在Rails中构建dropbox克隆。我在section 5,能够将应用程序连接到amazon web服务。我可以上传文件并将其存储在AWS上,但当我尝试下载它们时,会出现以下错误: AssetControllerGet中的OpenURI::HTTPError 301永久移动了无效的位置URI 这个问题是由另一个用户在这里发布的,但我无法找到修复方法。不管怎样,这是我的档案,如果有人能帮忙,我将不胜感激!此外,错误消息将突出显示“我的资产控制器”中的以下行: data=openURI.parseURI.encodeasset.uploaded_file.url 我的资产模型:Ruby on rails Rails应用程序,尝试从Amazon Web服务下载文件时出错,ruby-on-rails,ruby,amazon-web-services,paperclip,amazon,Ruby On Rails,Ruby,Amazon Web Services,Paperclip,Amazon,因此,我下面将在Rails中构建dropbox克隆。我在section 5,能够将应用程序连接到amazon web服务。我可以上传文件并将其存储在AWS上,但当我尝试下载它们时,会出现以下错误: AssetControllerGet中的OpenURI::HTTPError 301永久移动了无效的位置URI 这个问题是由另一个用户在这里发布的,但我无法找到修复方法。不管怎样,这是我的档案,如果有人能帮忙,我将不胜感激!此外,错误消息将突出显示“我的资产控制器”中的以下行: data=openUR
class Asset < ActiveRecord::Base
attr_accessible :user_id, :uploaded_file
belongs_to :user
has_attached_file :uploaded_file,
# :url => "/asset/get/:id",
:path => "assets/:id/:basename.:extension.",
# :path => "assets/:id/:basename.:extension",
:storage => :s3,
:s3_credentials => "#{::Rails.root}/config/amazon_s3.yml",
:bucket => "cheetahboxapp"
validates_attachment_size :uploaded_file, :less_than => 30.megabytes
validates_attachment_presence :uploaded_file
def file_name
uploaded_file_file_name
end
#def download_url(style = nil, include_updated_timestamp = true, asset)
# url = Paperclip::Interpolations.interpolate('/:class/:id/:style.:extension')
# include_updated_timestamp && asset.updated_at ? [url, asset.updated_at].compact.join(url.include?("?") ? "&" : "?") : url
#end
end
我的资产控制员:
class AssetsController < ApplicationController
before_filter :authenticate_user! #authenticate for user info before any method is called
def index
@assets = current_user.assets
end
def show
@asset = current_user.assets.find(params[:id])
end
def new
@asset = current_user.assets.new
end
def create
@asset = current_user.assets.new(params[:asset])
if @asset.save
redirect_to @asset, :notice => "Successfully created asset."
else
render :action => 'new'
end
end
def edit
@asset = current_user.assets.find(params[:id])
end
def update
@asset = current_user.assets.find(params[:id])
if @asset.update_attributes(params[:asset])
redirect_to @asset, :notice => "Successfully updated asset."
else
render :action => 'edit'
end
end
def destroy
@asset = current_user.assets.find(params[:id])
@asset.destroy
redirect_to assets_url, :notice => "Successfully destroyed asset."
end
def get
asset = current_user.assets.find_by_id(params[:id])
if asset
#Parse the url for special characters
data = open(URI.parse(URI.encode(asset.uploaded_file.url)))
send_data data, :filename => asset.uploaded_file_file_name
else
flash[:error] = "What're you going? Kiss my Assets"
redirect_to assets_path
end
end
end
我还使用了回形针3.5.2,以及aws-s3和aws sdk gems 您是否检查了创建S3存储桶的区域?如果不是us-east-1,请按中所示进行设置,也请参见其在us-west-2中的位置,我将在哪里设置此位置?我尝试在has_attached_文件下向我的模型中添加:region=>us-west-2,但仍然不起作用尝试设置环境变量好的,我找到了一些解决方法-我尝试在命令行中设置它,但没有起作用。因此,我创建了一个新的桶与美国标准作为地理位置,现在它的作品伟大!为了学习起见,我会继续努力找出解决问题的方法。谢谢你的帮助!