我正在编写一个应用程序来在Amazon S3上存储文件。我很接近,我能够保存和检索使用URL的文件。但是,因为这些链接是公开的我试图在我的assetscontroller中使用以下方法从S3中检索存储的文件。这个错误在Rails中意味着什么:“Errno :: ENOENT in AssetsController#get ...没有这样的文件或目录....”
的链接,这些文件可以查看/浏览器访问,但如果我用这个代码:
#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'
上怎么回事任何线索?
谢谢