File name too long @ rb_sysopen
0
Not solved Solved
over 1 year ago

Hi there, Does anyone know how to fix the File name too long @ rb_sysopen error ?

I start by fetching an image url in my form

image = open( params[:file] ) {|f| f.read } unless params[:file].nil?

then convert it to Base64 to avoid the null byte error:

image = Base64.encode64( web_contents )

I need a File object, so

file = File.new( image )

and then I get the error:

File name too long @ rb_sysopen - R0lGODlhjQHfAPf/ALkPrjMqKiIcHR4dIWZdUygjJoV6aDUpGv342fv21y8w...

Apparemment le nom ne peut pas dépasser 255 car. Or mon image fera tjs plus de 255. Vous auriez une idée ?

over 1 year ago

It can't be marked as resolved, but it is.

over 1 year ago

Here is how I fixed this issue.

The main reason was that creating a File object required to pass a local path.

To solve this issue, I had to save the image locally, then pass its path to create a new File.

image = open( params[:file] ) {|f| f.read } unless params[:file].nil?
image = save_file( image )
file = File.new( image )

here's the save_file method

def save_file(url)
    require 'open-uri'
    open('image.gif', 'wb') do |file|
      file << open( url ).read
    end
  end

hope this helps ;)

Cancel
Submit your answer