[Rails] Image upload problems
MCollins at seminolecountyfl.gov
MCollins at seminolecountyfl.gov
Tue Jan 4 20:41:41 GMT 2005
i'm new at rails and ruby so i haven't really seen this how-to on file
uploads; however, on a different subject away from the corrupted files, it
appears you're storing the actual images in the database as a blob? may i
ask why? i'm used to storing the images on the filesystem and putting the
path to that image in the database. tends to save on the database size
Berndt Jung wrote:
> So, like others on this list, I have started a picture store app. I
> have followed the directions in the "how to" section for file uploads,
> as well as the previous posters here. Basically, it seems as though
> it should be working, but the images become corrupt. I can view them,
> but they look awful. I tried resizing and formatting with RMagick
> (really cool extention), but it complained about the files I was
> sending it. So now I'm pretty sure that either ruby/rails is
> corrupting the files, or mysql.
>
> Anyone having similar issues?
>
> Thanks,
>
> Berndt
>
> MySql.dump
>
> CREATE TABLE `photos` (
> `id` int(11) unsigned NOT NULL auto_increment,
> `name` varchar(127) default NULL,
> `size` int(11) default NULL,
> `mime` varchar(127) default NULL,
> `picture` mediumblob NOT NULL,
> PRIMARY KEY (`id`),
> KEY `name` (`name`)
> ) TYPE=MyISAM
>
> rails code:
>
> def create
> #render_text @params['photo']['tmp_file'].local_path
> @photo = Photo.new do |p|
> p.name =
@params['photo']['tmp_file'].original_filename.gsub(/[^a-zA-Z0-9.]/,
> '_')
> p.size = @params['photo']['tmp_file'].size
> p.mime = @params['photo']['tmp_file'].content_type
> p.picture = @params['photo']['tmp_file'].read
> end
> @params.delete("photo" => "tmp_file")
> if @photo.save
> redirect_to :action => "show/" + @photo.id.to_s
> else
> render "photo/edit"
> end
> end
>
> def show
> #@image = Photo.find(@params['id'])
> #send_data @image.picture, :filename => @image.name, :type =>
> @image.mime, :disposition => "inline"
> @image = Photo.find(@params["id"])
> @response.headers["Content-type"] =
@image.mime
> render_text @image.picture
> end
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
_______________________________________________
Rails mailing list
Rails at lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
--****Florida has a very broad Public Records Law. Virtually all written
communications to or from State and Local Officials and employees are
public records available to the public and media upon request. Seminole
County policy does not differentiate between personal and business emails.
E-mail sent on the County system will be considered public and will only
be withheld from disclosure if deemed confidential pursuant to State
Law.****
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://one.textdrive.com/pipermail/rails/attachments/20050104/5dd50cf7/attachment.html
More information about the Rails
mailing list