Problems with File_column

Hi,

Rails - newbie here…

I’m setting up an app and am trying to use file_column to upload a
picture with an item and I’m running into several problems.

(Background: I’m running Locomotive Rails under OS X 10.4.4, and using
Safari)

I followed the directions to add the necessary items, then found out
that I had to add the item to make the form tag be a multipart item.
(Sebastian - you may want to update your docs for this!)

However, when I changed the start_form_tag item to be:

<%= start_form_tag :action => ‘create’, :multipart => true %>

I get a form tag like:

which leads to an error. I can change it to:

<%= start_form_tag({:action => ‘create’}, :multipart => true) %>

which generates the correct form tag. Why does the first one not work?

Then, when I tried to submit, Safari would just time out. I found an
item about changing the lighttp.conf to work with Safari, but that
didn’t help.

If I then tried Firefox, I would then get an error instead:

same file:
/Users/john/Desktop/Mytest/public/…/config/…/public/team/image/tmp/1137961236.548784.3649/IMG_0008.JPG
and
/Users/john/Desktop/Mytest/public/…/config/…/public/team/image/tmp/1137961236.548784.3649/IMG_0008.jpg

I did some digging and found out that if the original file is in
UPPERCASE, then that error results. If I choose a file that has
lowercase, the file uploads fine in both Firefox and Safari. (In
Firefox, you can edit and change the filename to be lowercase and it
will work).

Is there any way around this problem?!?

Thanks!

John T. wrote:

Hi,

Rails - newbie here…

One more quick question…

On my Edit form, (which is using the same form as for the “new” item),
the field for the image is showing “no image selected” (which sort of
makes sense). Can I just show the existing file name somehow? Or image?

Also, I had to change the the start_form_tag for my edit page from:

<%= start_form_tag :action => ‘update’, :id => @team, :multipart => true
%>

To:

<%= start_form_tag({:action => ‘update’, :id => @team}, :multipart =>
true) %>

to get the proper tag. And through some trial and error I found I
had to put the braces where they are (which I’m sure is just Ruby syntax
that I’m missing…)

Thanks again.

Not a stupid question. If you are running lighttpd, you have to modify
it to
add the following to your lighttpd.conf:

for safari file uploads

$HTTP[“useragent”] =~ “^(.MSIE.)|(.AppleWebKit.)$” {
server.max-keep-alive-requests = 0
}

If you are running Locomotive, open

/Applications/Locomotive/Bundles/lighttpd<something_or_oter>.bundle/Contents
/Resources/base_lighttpd.conf

And make the change there. That should get you going. Oh, and don’t
forget
to bounce the server :slight_smile:

On 1/22/06, John T. [email protected] wrote:

makes sense). Can I just show the existing file name somehow? Or image?

[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

The reason for the curly braces is that the method takes two hashes as
arguments. Without the curly braces, Ruby assumes that you intended
the last key/value pair to be a part of the first hash, when in
reality, its part of the second.

Also, file_column_field doesn’t tell you whats currently there, but
you could always show it manually like:

<%=link_to “current contents”, url_for_file_column(“model”, “field”)
if @model.field %>


Kyle M.
Chief Technologist
E Factor Media // FN Interactive
[email protected]
1-866-263-3261

Steve R. wrote:

Not a stupid question. If you are running lighttpd, you have to modify
it to
add the following to your lighttpd.conf:

for safari file uploads

$HTTP[“useragent”] =~ “^(.MSIE.)|(.AppleWebKit.)$” {
server.max-keep-alive-requests = 0
}

If you are running Locomotive, open

/Applications/Locomotive/Bundles/lighttpd<something_or_oter>.bundle/Contents
/Resources/base_lighttpd.conf

And make the change there. That should get you going. Oh, and don’t
forget
to bounce the server :slight_smile:

Ah… thanks for that! I added that line into the wrong place - in:

Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/rails-1.0.0/configs

John T. wrote:

Hmm. Unfortunately, that does fix the error:

Errr… Make that does not fix the error…

A couple of references that may or may not fix your problem:

http://wiki.rubyonrails.com/rails/pages/HowToUseFileColumn

http://wiki.rubyonrails.com/rails/pages/UploadingFilesWithFileColumn

Search the forum ( http://www.ruby-forum.com/forum/3) – I seem to
recall a
few issues like this before.

Also, look at the source to see where the case translation is taking
place
on the extension. That may provide a clue to what the problem is and
suggest
a fix.

Steve R. wrote:

Not a stupid question. If you are running lighttpd, you have to modify
it to
add the following to your lighttpd.conf:

for safari file uploads

$HTTP[“useragent”] =~ “^(.MSIE.)|(.AppleWebKit.)$” {
server.max-keep-alive-requests = 0
}

If you are running Locomotive, open

/Applications/Locomotive/Bundles/lighttpd<something_or_oter>.bundle/Contents
/Resources/base_lighttpd.conf

And make the change there. That should get you going. Oh, and don’t
forget
to bounce the server :slight_smile:

Hmm. Unfortunately, that does fix the error:

same file:
/Users/john/Desktop/Mytest/public/…/config/…/public/team/image/tmp/1137963285.522411.3748/IMG_0202.JPG
and
/Users/john/Desktop/Mytest/public/…/config/…/public/team/image/tmp/1137963285.522411.3748/IMG_0202.jpg

which deals with the uppercase filename/extension…

Steve R. wrote:

A couple of references that may or may not fix your problem:

Peak Obsession

Peak Obsession

Search the forum ( http://www.ruby-forum.com/forum/3) – I seem to
recall a
few issues like this before.

Also, look at the source to see where the case translation is taking
place
on the extension. That may provide a clue to what the problem is and
suggest
a fix.

Thanks for those links, unfortunately there isn’t anything there about
the case problem. I had done a search on the forum and did see one post
about the problem, but without a solution. I guess it’s time to start
looking at the source :slight_smile:

Thanks again.

jt

In file_column.rb, find this code:

def store_upload(file)
  @tmp_dir = FileColumn.generate_temp_name
  @dir = File.join(tmp_base_dir, @tmp_dir)
  FileUtils.mkdir(@dir)

  @filename = FileColumn::sanitize_filename(file.original_filename)
  local_file_path = File.join(tmp_base_dir,@tmp_dir,@filename)

Prior to the @filename = stick:

RAILS_DEFAULT_LOGGER.debug “original filename =
#{file.original_filename}”

After the @filename = stick:

RAILS_DEFAULT_LOGGER.debug “sanitized filename = #{@filename}”

After the local_file_path = stick:

RAILS_DEFAULT_LOGGER.debug “Local file path = #{local_file_path}”

Let’s see if the case translation is happening there. Sometimes a few
print
statements make a world of difference.

Steve R. wrote:

In file_column.rb, find this code:

Let’s see if the case translation is happening there. Sometimes a few
print
statements make a world of difference.

This is what I get:

original filename = IMG_0095.JPG
sanitized filename = IMG_0095.JPG
Local file path =
/Users/john/Desktop/Mytest/public/…/config/…/public/team/image/tmp/1137978200.835250.3798/IMG_0095.JPG

The error is being generated from this line in file_column.rb:

FileUtils.mv(local_file_path, new_local_file_path) unless
new_local_file_path == local_file_path

The only difference between the two paths is the case of the extension
(JPG vs jpg). I suppose I could change the test to compare like-cased
paths…

Yes, that did avoid the error in my case, but I suppose in the general
case, in other OS’s where it handles case of files differently, it may
not be quite correct.

(an aside… that sure is a convoluted path that is generated to the file

  • up and back down and up and down into the same directory…)

Thanks!

On 3/9/06, Courtenay [email protected] wrote:

If anyone’s still having this problem, I solved it and only just found
this thread, and thought I’d provide some actual code. It’s a
one-line fix.

Hey! I recognize that fix! :slight_smile:

Glad it helped…

jt

If anyone’s still having this problem, I solved it and only just found
this thread, and thought I’d provide some actual code. It’s a
one-line fix.

Change

FileUtils.mv(local_file_path, new_local_file_path) unless new_local_file_path == local_file_path

to

FileUtils.mv(local_file_path, new_local_file_path) unless new_local_file_path.downcase == local_file_path.downcase

The code here is comparing the filename of the original file, and its
sanitized version. In some cases where there was an uppercase upload,
your case-(in)sensitive OS will spit an error. This fix doesn’t have
any negative effect, because we’re just sanitizing filenames, nothing
else.

Good luck!

courtenay
http://blog.caboo.se