Amazon S3 にファイルを保存するアプリを作成しています。URLを使用してファイルを保存および取得できます。ただし、これらのリンクは公開されているため、アセットコントローラーで次のメソッドを使用して、S3 から保存されたファイルを取得しようとしています。
リンクとして、これらのファイルはブラウザで表示/アクセスできますが、このコードを使用すると:
#This action will let the users download the files (after a simple authorization check)
def get
asset = current_user.assets.find_by_id(params[:id])
if asset
#Parse the URL for special characters first before downloading
data = open("#{URI.parse(URI.encode(asset.uploaded_file.url))}")
#then again, use the "send_data" method to send the above binary "data" as file.
send_data data, :filename => asset.uploaded_file_file_name
else
flash[:error]="Access Violation"
redirect_to assets_path
end
終わり
ブラウザで次のエラーが表示されます。
Errno::ENOENT in AssetsController#get
No such file or directory - http://s3.amazonaws.com/BUCKETNAME/assets/29/FILENAME.jpeg? 1339979591
S3 管理コンソールにログインしているときに S3 サイトのリソースをクリックすると、ブラウザにファイルが表示され、そのリンクが
https://s3.amazonaws.com/BUCKETNAME/assets/29/FILENAME.jpeg? AWSAccessKeyId=XXXXXXXXXXXExpires=1340003832&Signature=XXXXXXXXXXXXXXXXXX-amz-security- token=XXXXXXXXX//////////XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
存在しますが、アプリからアクセスできません
ブラウザからのアプリケーション トレースは次のとおりです。
app/controllers/assets_controller.rb:99:in `initialize'
app/controllers/assets_controller.rb:99:in `open'
app/controllers/assets_controller.rb:99:in `get'
何が起こっているのか手がかりはありますか?
ありがとう