# File upload failed. Try a different image?

**URL:** <https://www.ruby-forum.com/t/file-upload-failed-try-a-different-image/178394>\
**Category:** Rails\
**Created:** [November 3, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/file-upload-failed-try-a-different-image/178394 "2009-11-03T22:30:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [November 3, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/file-upload-failed-try-a-different-image/178394/1 "2009-11-03T22:30:23Z")

</div>

Evening all!

I’ve decided to give it another shot with the image upload  
functionality provided with the tutorial ‘RailsSpace’…

I’ve got further, in the fact that it recognizes an upload attempt,  
but fails with the message:

File upload failed. Try a different image?

I used a small-ish sized file (28k)

The max upload size is 1mb as seen within the def valid\_file? action:

if @image.size \> 1.megabyte  
errors.add(:image, “can’t be bigger than 1 megabyte”)  
return false

The error message I’m now getting is based within the  
'successful\_conversion? action:

def successful\_conversion?  
# Prepare the filenames for the conversion.  
source = File.join(“tmp”, “#{@user.username}\_full\_size”)  
full\_size = File.join(DIRECTORY, filename)  
thumbnail = File.join(DIRECTORY, thumbnail\_name)  
# Ensure that small and large images both work by writing to a  
normal file.  
# (Small files show up as StringIO, larger ones as Tempfiles.)  
File.open(source, “wb”) { |f| f.write(@image.read) }  
# Convert the files.  
img = system("#{convert} #{source} -resize #{IMG\_SIZE} #  
{full\_size}")  
thumb = system("#{convert} #{source} -resize #{THUMB\_SIZE} #  
{thumbnail}")  
File.delete(source) if File.exists?(source)  
# Both conversions must succeed, else it’s an error.  
unless img and thumb  
errors.add\_to\_base(“File upload failed. Try a different  
image?”)  
return false  
end  
return true  
end

However - i dont understand why this hasn’t uploaded…

Anyone else had this problem???

Thanks a lot for reading!

---

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [November 3, 2009, 10:39pm UTC](https://www.ruby-forum.com/t/file-upload-failed-try-a-different-image/178394/2 "2009-11-03T22:39:10Z")

</div>

On Nov 3, 9:29 pm, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> However - i dont understand why this hasn’t uploaded…
> 
> Anyone else had this problem???

Have you tried stepping through the code and seeing at which point  
this fails?

Fred

---

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [November 3, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/file-upload-failed-try-a-different-image/178394/3 "2009-11-03T22:45:37Z")

</div>

Yeah - Although i’m new to this, I guessed its got up to the point  
where it checks directories, and converts the image into a thumb.

If it hasn’t converted them, it throws the error.

Thats how i read it. If that’s wrong, fair enough, but I’m not sure  
how exactly to resolve this…

---

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [November 3, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/file-upload-failed-try-a-different-image/178394/4 "2009-11-03T22:51:28Z")

</div>

SUCCESS!!! WOOOO!!! 🙂

It turns out my convert is stored in “/usr/local/bin/convert”

however the action in the tutorial sets it as: usr/bin/convert.

Avatar is now uploaded.

Thanks for the response though!!!

On 3 Nov, 21:44, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
