Re: Beginners: File uploads and rendering images to the database

Thanks for the idea jnylund.  I implemented it, however, I'm getting the same result.  The page displays as expected, however, the picture is replaced with the "alt" empty box for the jpeg.

I have checked the actual db using the mySQLQueryBrowser from the mySQL people.  The picture renders properly using that tool and everything else in the database looks just fine.  And yes, the "id" sent is correct, so I'm looking at the right record.

I've attached the output from my latest debug run.  Anyone have any ideas?

Thanks for the help!

Processing PicturesController#code_picture (for 127.0.0.1 at 2007-11-15 18:35:12) [GET]

  Session ID: 1e42e86cde6b2e507e4bb83c838bf8c2

  Parameters: {"action"=>"code_picture", "id"=>"3", "controller"=>"pictures"}

"=>"pictures"}

  Picture Columns (0.000000)   SHOW FIELDS FROM pictures

  Picture Load (0.000000)   SELECT * FROM pictures WHERE (pictures.`id` = 3)

Sending data small.jpg

Completed in 12.01600 (0 reqs/sec) | Rendering: 0.00000 (0%) | DB: 0.00000 (0%) | 200 OK [http://localhost/pictures/code_picture?id=3]

Re: Beginners: File uploads and rendering images to the database

I did just notice that the last line above returns a 200 status, however the URL is [http://localhost/pictures/code_picture?id=3] rather than [http://localhost:3000/pictures/code_picture?id=3] *the port number changed*.... Is this significant?

Thanks,
B.

Re: Beginners: File uploads and rendering images to the database

!!!  SOLUTION FOUND !!!

In frustration, rather than just sound reasoning, I was stepping deeply in to the code looking for anything at all.  I finally noticed that the binary blob size was only 64K when in fact the filesize was over 190Kb.  I then figured that there was no appropriate EOF in the file (or whatever JPG uses). 

Long story short...

I migrated my database (mySQL) to use a :LIMIT of 4.megabytes.

I then stepped through the code to load a new image, and VOILA!  The image was as expected.

Thanks again for the tutorial and the help.

Now... for the next problem to arise!

Re: Beginners: File uploads and rendering images to the database

Final note (I hope)

With higher resolution cameras, and thus larger files, changing just the :limit value may not be enough.  mySQL has a default packet limitation (the size of a single, entire query) of 1Mb.  A simple change to the mySQL configuration file changes the client side value.  I changed mine to 8Mb and everything worked again for larger pictures.

See: http://dev.mysql.com/doc/refman/5.0/en/ … large.html

for more info.

45

Re: Beginners: File uploads and rendering images to the database

I have been trying to get over the blank image field error and I have been using the code supplied by others earlier in the thread.

where does this code go? Can someone supply the entire file that has this code contents so I understand its placement?

unless params[:photo].blank?
  @photo.update_attributes(params[:photo])
end

Thanks, hey!

Last edited by mc (2007-11-19 20:30:27)

Re: Beginners: File uploads and rendering images to the database

Is there any way to use RMagick to resize these photo uploads on the way to the database?  I've been spending hours trying but can't seem to figure it out.

Something like this, although it doesn't work:

require 'RMagick'

class Photo < ActiveRecord::Base
  belongs_to :user
     
  def image_file=(input_data)
    self.filename = input_data.original_filename
    self.content_type = input_data.content_type.chomp
    self.full = input_data.read   
    img = Magick::Image.read(input_data).first
    self.thumbnail = img.thumbnail(125,125)
  end

end

Last edited by bensie (2007-11-23 20:07:25)

47

Re: Beginners: File uploads and rendering images to the database

When in list view, the photos show up at the top under the heading, then the line by line descriptive columns and contents show up under them.
How do I get the photo images to be located in the column I want them in , and in my case, as the first item in the column list as displayed line by line?

Re: Beginners: File uploads and rendering images to the database

Hi bensie.

Try this.

picture = Magick::Image.from_blob(input_data.read).first

http://www.imagemagick.org/RMagick/doc/ … #from_blob

Last edited by andy_dick (2007-12-13 13:37:30)

Re: Beginners: File uploads and rendering images to the database

Any chance of updating this to Rails 2.0?
Nothing works for me... I mean even generating scaffolds.. I get photo_admins!
...this rails is too much headache.

"Iwana ga hana"

Re: Beginners: File uploads and rendering images to the database

drozzy wrote:

Any chance of updating this to Rails 2.0?
Nothing works for me... I mean even generating scaffolds.. I get photo_admins!
...this rails is too much headache.

Same here, fell totally apart around "Creating a new photo".

Would be nice to redo the index for rails 2.


Anyone have a link to a rails 2 tutorial?

I am currently on a windows machine with netbeans (did the one tut for rails 2 on their site)

Re: Beginners: File uploads and rendering images to the database

Hi

When I try scaffold photo to photo_admin (Rails 2.1) I get this error:

wrong number of arguments (1 for 2)

So I don't get CRUD actions in photo_admin_controller.

Whats the 2.1 way of scaffolding a controller to an already existing model?

Thanks!  I hope to be position soon to give advice back to the community! smile

Re: Beginners: File uploads and rendering images to the database

hi all I am a newbie to RoR , i have tried out this tutorial but got stuck.
the "ruby script/generate scaffold photo photo_admin" didn't create any method in my photo_admin contoller. i'm using rails 2.0. Is there any sintax difference in rails 2.0

pls tell me what "ruby script/generate scaffold photo photo_admin" does ? will it create two controllers -> photo and photo_admin??!!

Last edited by jerinantony1 (2008-10-10 03:18:08)

Re: Beginners: File uploads and rendering images to the database

This tutorial RAWKS.

Just sayin'

But if you want it / Then you must find it
But when you have it / There'll be no need for it

Re: Beginners: File uploads and rendering images to the database

When i tried doing the first steps, this happened

class CreatePhotos < ActiveRecord::Migration  
   def self.up    
      create_table :photos do |t|      
         t.column :description, :string    
         t.column :content_type, :string 
         t.column :filename, :string 
         t.column :binary_data, :binary  
   end
C:\rails\rails_apps\home>rake db:migrate
(in C:/rails/rails_apps/home)
rake aborted!
./db/migrate//001_create_photos.rb:8: syntax error, unexpected $end, expecting k
END

(See full trace by running task with --trace)

i also tried putting another 'end' but it's another issue:

class CreatePhotos < ActiveRecord::Migration  
   def self.up    
      create_table :photos do |t|      
         t.column :description, :string    
         t.column :content_type, :string 
         t.column :filename, :string 
         t.column :binary_data, :binary  
   end
end


C:\rails\rails_apps\home>rake db:migrate
(in C:/rails/rails_apps/home)
rake aborted!
./db/migrate//001_create_photos.rb:9: syntax error, unexpected $end, expecting k
END

(See full trace by running task with --trace)

Please help me out, I'm stuck on this issue sad thanks.

Re: Beginners: File uploads and rendering images to the database

I am very new and need to upload pictures for a project I am doing. 

I don't understand where you type this command into... I tried in the command prompt but it doesn't recognize it?  Usually I use rails generate scaffold to make tables...

ruby script/generate model photo

I am kinda lost

Re: Beginners: File uploads and rendering images to the database

Hi Jordan

You can find here a very helpful railcast here http://railscasts.com/episodes/253-carr … le-uploads to learn how to upload image in your app using Carrierwave gem.

These ones are about Image manipulation using Carrierwave to upload and RMagick for manipulation : http://railscasts.com/episodes/374-image-manipulation

These ones are about upload and manipulation (cropping, resizing...) using JQuery...
http://railscasts.com/episodes/381-jquery-file-upload
http://railscasts.com/episodes/182-crop … es-revised

Hope this helps
Cheers