Getting “Errno::ENOENT: No such file or directory @ rb_sysopen” while reading the CSV file from the AWS S3

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

I have application which is deployed to Heroku. I have added functionality for uploading users thorough the CSV. For this I have provided CSV upload functionality (Used Paperclip gem).

Here is my code for reading the file and creating new user

def import(file)   CSV.foreach(file.path, headers: true) do |row|       row_hash = row.to_hash.values       data = row_hash[0].split("\t")       .       .       . end 

On the local it is working fine. But on the heroku it is giving me following error

Errno::ENOENT: No such file or directory @ rb_sysopen - https://s3.amazonaws.com/..../..../sample_csv(2).csv 

I referred following links Errno::ENOENT (No such file or directory) in amazon-s3

File reading from Amazon server, ruby on rails, no match route

but didn't any success. For more debugging, I tried same url from my local rails console and it is giving me the same error.

2.2.2 :008 > cp = "https://s3.amazonaws.com/..../..../sample_csv(2).csv" 2.2.2 :008 > f = File.open(cp, "r") Errno::ENOENT: No such file or directory @ rb_sysopen - https://s3.amazonaws.com 

Also tried open uri http://ruby-doc.org/stdlib-2.1.0/libdoc/open-uri/rdoc/OpenURI.html.

I can download the same file from the browser.

Can any one let me know how to resolve this error. Is there any bucket permission issue (I have already provided open access for the bucket).

回答1:

Try this

require 'open-uri' require 'csv'  def import(file)   CSV.new(open(file), :headers => :true).each do |row|  #First open the file using open       row_hash = row.to_hash.values       data = row_hash[0].split("\t")       .       .       . end 

For more info you can refer this link



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!