我正在編寫一個應用程序來在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'
上怎麼回事任何線索?
謝謝