正在获取 Errno::ENOENT:没有这样的文件或目录 @ rb_sysopen 当试图在 Roo gem 中打开远程文件 url(Ruby on rails)
Getting Errno::ENOENT: No such file or directory @ rb_sysopen When trying to open remote file url in Roo gem(Ruby on rails)
我在尝试使用 roo gem 打开文件导入数据时在 AWS s3 存储中存储了一个文件,它引发了以下错误 Errno::ENOENT: No such file or directory @ rb_sysopen
def self.import(file, user_id)
imported_file = ImportedFile.find(file)
spreadsheet = Roo::Spreadsheet.open(open(imported_file.file_url), extension: :csv)
spreadsheet = Roo::Spreadsheet.open(imported_file.file)
header = spreadsheet.row(1)//raising error here
end
我什至也试过这个
spreadsheet = Roo::Spreadsheet.open(imported_file.file_url)
日志中出现以下错误
Errno::ENOENT: No such file or directory @ rb_sysopen - /uploads/imported_files/7a6f0463-b3cd-48f8-a579-bc27951242fe/13c96e3e-d3f3-4ed8-8d9a-b9ea03c0cc8c.csv
要打开 URL,您应该首先需要 open-uri
库:
require 'open-uri'
看例子:
open('http://example.com/')
# throws Errno::ENOENT: No such file or directory @ rb_sysopen - http://example.com/
require 'open-uri'
open('http://example.com/')
# opens the website
下面的代码终于为我工作了。
spreadsheet = Roo::Spreadsheet.open(open(imported_file.file_url), extension: File.extname(imported_file.file_url).gsub('.','').to_sym) rescue nil
我在尝试使用 roo gem 打开文件导入数据时在 AWS s3 存储中存储了一个文件,它引发了以下错误 Errno::ENOENT: No such file or directory @ rb_sysopen
def self.import(file, user_id)
imported_file = ImportedFile.find(file)
spreadsheet = Roo::Spreadsheet.open(open(imported_file.file_url), extension: :csv)
spreadsheet = Roo::Spreadsheet.open(imported_file.file)
header = spreadsheet.row(1)//raising error here
end
我什至也试过这个
spreadsheet = Roo::Spreadsheet.open(imported_file.file_url)
日志中出现以下错误
Errno::ENOENT: No such file or directory @ rb_sysopen - /uploads/imported_files/7a6f0463-b3cd-48f8-a579-bc27951242fe/13c96e3e-d3f3-4ed8-8d9a-b9ea03c0cc8c.csv
要打开 URL,您应该首先需要 open-uri
库:
require 'open-uri'
看例子:
open('http://example.com/')
# throws Errno::ENOENT: No such file or directory @ rb_sysopen - http://example.com/
require 'open-uri'
open('http://example.com/')
# opens the website
下面的代码终于为我工作了。
spreadsheet = Roo::Spreadsheet.open(open(imported_file.file_url), extension: File.extname(imported_file.file_url).gsub('.','').to_sym) rescue nil