I''m using the excellent flex_image plugin for a new project and have
hit a bit of a road block.
I need to import a large number of images and so have been looking at
an alternative to just using a simple html form to upload the images
one at a time.
something like..
fp = open(''one.jpg'',''rb'')
file = fp.read
p = Picture.create(:data=>file)
gives an error..
FlexImage::Model::InvalidImage: Uploaded file contains no binary
data. Be sure that {:multipart => true} is set on your form.
from ./script/../config/../config/../vendor/plugins/flex_image/
lib/flex_image/model.rb:153:in `data=''
Anyone have an idea how I can get round this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Can you use url to the images you want to import? Flex image is supporting that otherwise you can hack the code for local file system. For urls; Picture.create(:data => "http://localhost/import/1.jpg") Gokhan Arli www.sylow.net kevin evans wrote:> I''m using the excellent flex_image plugin for a new project and have > hit a bit of a road block. > > I need to import a large number of images and so have been looking at > an alternative to just using a simple html form to upload the images > one at a time. > > something like.. > > fp = open(''one.jpg'',''rb'') > file = fp.read > p = Picture.create(:data=>file) > > > gives an error.. > > FlexImage::Model::InvalidImage: Uploaded file contains no binary > data. Be sure that {:multipart => true} is set on your form. > from ./script/../config/../config/../vendor/plugins/flex_image/ > lib/flex_image/model.rb:153:in `data='' > > Anyone have an idea how I can get round this?-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This seems to work fine in the batch processor I''m using with
FlexImage:
@photo = Photo.new()
@photo.data = File.new("/path/to/image/#{image}")
@photo.save
Where image is just the filename of the image. Took a lot of trial and error
to get to that point, but seems to work fine (this is a little longhand
because this is just small subset of the batch ... I''ve also got a lot
of
IPTC/EXIF fiddling in there).
On 6/4/07, kevin evans <kwevans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> I''m using the excellent flex_image plugin for a new project and
have
> hit a bit of a road block.
>
> I need to import a large number of images and so have been looking at
> an alternative to just using a simple html form to upload the images
> one at a time.
>
> something like..
>
> fp = open(''one.jpg'',''rb'')
> file = fp.read
> p = Picture.create(:data=>file)
>
>
> gives an error..
>
> FlexImage::Model::InvalidImage: Uploaded file contains no binary
> data. Be sure that {:multipart => true} is set on your form.
> from ./script/../config/../config/../vendor/plugins/flex_image/
> lib/flex_image/model.rb:153:in `data=''
>
> Anyone have an idea how I can get round this?
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks for the replies guys, Chris, I tried your method under irb and get..>> @picture = Picture.new()=> #<Picture:0x3dfa310 @new_record=true, @invalid_image=false, @attributes={"caption"=>nil, "data"=>nil}>>> @picture.caption = "A test"=> "A test">> @picture.data = File.new("/Users/kwe/Desktop/two.jpg")NoMethodError: undefined method `size'' for #<File:/Users/kwe/Desktop/ two.jpg> from ./script/../config/../config/../vendor/plugins/flex_image/ lib/flex_image/model.rb:156:in `data='' from (irb):3>>I''m not that familiar with ruby, my File class does not seem to have a .size method !?!? ie.>> @f = File.new(''/Users/kwe/Desktop/two.jpg'')=> #<File:/Users/kwe/Desktop/two.jpg>>> @f.sizeNoMethodError: undefined method `size'' for #<File:/Users/kwe/Desktop/ two.jpg> from (irb):11>> @f.stat=> #<File::Stat dev=0xe000002, ino=1008872, mode=0100644, nlink=1, uid=501, gid=501, rdev=0x0, size=305935, blksize=4096, blocks=600, atime=Tue Jun 05 16:17:54 +0100 2007, mtime=Thu Apr 26 16:35:18 +0100 2007, ctime=Tue Jun 05 16:17:46 +0100 2007>>>Any ideas? thanks Kevin On Jun 5, 3:16 pm, "Chris Vannoy" <dumm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This seems to work fine in the batch processor I''m using with FlexImage: > > @photo = Photo.new() > > @photo.data = File.new("/path/to/image/#{image}") > > @photo.save > > Where image is just the filename of the image. Took a lot of trial and error > to get to that point, but seems to work fine (this is a little longhand > because this is just small subset of the batch ... I''ve also got a lot of > IPTC/EXIF fiddling in there). > > On 6/4/07, kevin evans <kwev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m using the excellent flex_image plugin for a new project and have > > hit a bit of a road block. > > > I need to import a large number of images and so have been looking at > > an alternative to just using a simple html form to upload the images > > one at a time. > > > something like.. > > > fp = open(''one.jpg'',''rb'') > > file = fp.read > > p = Picture.create(:data=>file) > > > gives an error.. > > > FlexImage::Model::InvalidImage: Uploaded file contains no binary > > data. Be sure that {:multipart => true} is set on your form. > > from ./script/../config/../config/../vendor/plugins/flex_image/ > > lib/flex_image/model.rb:153:in `data='' > > > Anyone have an idea how I can get round this?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for reminding me, I forgot I adjusted FlexImage to handle this
(sorry).
In flex_image/lib/flex_image/model.rb , there''s a line (156) in the
data=(file) method that looks like this:
if file.size > 0
The problem I ran into was the one you ran into, file.size doesn''t work
with
File.new (apparently) ... however, file.stat.size does.
So, I added this above that line:
begin
size = file.stat.size
rescue
size = file.size
end
and replaced that line with:
if size > 0
The whole thing:
begin
size = file.stat.size
rescue
size = file.size
end
if size > 0
Sorry again that I forgot to mention that. And yes, there''s probably a
more
elegant way than fiddling directly in the FlexImage code. In fact,
there''s
probably a more elegant way to handle this in general (feel free to fill me
in).
On 6/5/07, kevin evans <kwevans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> Thanks for the replies guys,
>
> Chris,
>
> I tried your method under irb and get..
>
> >> @picture = Picture.new()
> => #<Picture:0x3dfa310 @new_record=true, @invalid_image=false,
> @attributes={"caption"=>nil, "data"=>nil}>
> >> @picture.caption = "A test"
> => "A test"
> >> @picture.data = File.new("/Users/kwe/Desktop/two.jpg")
> NoMethodError: undefined method `size'' for
#<File:/Users/kwe/Desktop/
> two.jpg>
> from ./script/../config/../config/../vendor/plugins/flex_image/
> lib/flex_image/model.rb:156:in `data=''
> from (irb):3
> >>
>
> I''m not that familiar with ruby, my File class does not seem to
have
> a .size method !?!?
>
> ie.
> >> @f = File.new(''/Users/kwe/Desktop/two.jpg'')
> => #<File:/Users/kwe/Desktop/two.jpg>
> >> @f.size
> NoMethodError: undefined method `size'' for
#<File:/Users/kwe/Desktop/
> two.jpg>
> from (irb):11
> >> @f.stat
> => #<File::Stat dev=0xe000002, ino=1008872, mode=0100644, nlink=1,
> uid=501, gid=501, rdev=0x0, size=305935, blksize=4096, blocks=600,
> atime=Tue Jun 05 16:17:54 +0100 2007, mtime=Thu Apr 26 16:35:18 +0100
> 2007, ctime=Tue Jun 05 16:17:46 +0100 2007>
> >>
>
> Any ideas?
>
> thanks
> Kevin
>
> On Jun 5, 3:16 pm, "Chris Vannoy"
<dumm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > This seems to work fine in the batch processor I''m using with
FlexImage:
> >
> > @photo = Photo.new()
> >
> > @photo.data = File.new("/path/to/image/#{image}")
> >
> > @photo.save
> >
> > Where image is just the filename of the image. Took a lot of trial and
> error
> > to get to that point, but seems to work fine (this is a little
longhand
> > because this is just small subset of the batch ... I''ve also
got a lot
> of
> > IPTC/EXIF fiddling in there).
> >
> > On 6/4/07, kevin evans
<kwev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> >
> >
> > > I''m using the excellent flex_image plugin for a new
project and have
> > > hit a bit of a road block.
> >
> > > I need to import a large number of images and so have been
looking at
> > > an alternative to just using a simple html form to upload the
images
> > > one at a time.
> >
> > > something like..
> >
> > > fp = open(''one.jpg'',''rb'')
> > > file = fp.read
> > > p = Picture.create(:data=>file)
> >
> > > gives an error..
> >
> > > FlexImage::Model::InvalidImage: Uploaded file contains no binary
> > > data. Be sure that {:multipart => true} is set on your form.
> > > from
> ./script/../config/../config/../vendor/plugins/flex_image/
> > > lib/flex_image/model.rb:153:in `data=''
> >
> > > Anyone have an idea how I can get round this?
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Chris, That works great - thanks again. Kevin On 6/5/07, Chris Vannoy <dummied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks for reminding me, I forgot I adjusted FlexImage to handle this > (sorry). > > In flex_image/lib/flex_image/model.rb , there''s a line (156) in the > data=(file) method that looks like this: > > if file.size > 0 > > The problem I ran into was the one you ran into, file.size doesn''t work > with File.new (apparently) ... however, file.stat.size does. > > So, I added this above that line: > > begin > size = file.stat.size > rescue > size = file.size > end > > and replaced that line with: > > if size > 0 > > > The whole thing: > > begin > size = file.stat.size > rescue > size = file.size > end > > if size > 0 > > > Sorry again that I forgot to mention that. And yes, there''s probably a > more elegant way than fiddling directly in the FlexImage code. In fact, > there''s probably a more elegant way to handle this in general (feel free to > fill me in). > > > > > On 6/5/07, kevin evans <kwevans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Thanks for the replies guys, > > > > Chris, > > > > I tried your method under irb and get.. > > > > >> @picture = Picture.new() > > => #<Picture:0x3dfa310 @new_record=true, @invalid_image=false, > > @attributes={"caption"=>nil, "data"=>nil}> > > >> @picture.caption = "A test" > > => "A test" > > >> @picture.data = File.new("/Users/kwe/Desktop/two.jpg") > > NoMethodError: undefined method `size'' for #<File:/Users/kwe/Desktop/ > > two.jpg> > > from ./script/../config/../config/../vendor/plugins/flex_image/ > > lib/flex_image/model.rb:156:in `data='' > > from (irb):3 > > >> > > > > I''m not that familiar with ruby, my File class does not seem to have > > a .size method !?!? > > > > ie. > > >> @f = File.new(''/Users/kwe/Desktop/two.jpg'') > > => #<File:/Users/kwe/Desktop/two.jpg> > > >> @f.size > > NoMethodError: undefined method `size'' for #<File:/Users/kwe/Desktop/ > > two.jpg> > > from (irb):11 > > >> @f.stat > > => #<File::Stat dev=0xe000002, ino=1008872, mode=0100644, nlink=1, > > uid=501, gid=501, rdev=0x0, size=305935, blksize=4096, blocks=600, > > atime=Tue Jun 05 16:17:54 +0100 2007, mtime=Thu Apr 26 16:35:18 +0100 > > 2007, ctime=Tue Jun 05 16:17:46 +0100 2007> > > >> > > > > Any ideas? > > > > thanks > > Kevin > > > > On Jun 5, 3:16 pm, "Chris Vannoy" <dumm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > This seems to work fine in the batch processor I''m using with > > FlexImage: > > > > > > @photo = Photo.new() > > > > > > @photo.data = File.new("/path/to/image/#{image}") > > > > > > @photo.save > > > > > > Where image is just the filename of the image. Took a lot of trial and > > error > > > to get to that point, but seems to work fine (this is a little > > longhand > > > because this is just small subset of the batch ... I''ve also got a lot > > of > > > IPTC/EXIF fiddling in there). > > > > > > On 6/4/07, kevin evans <kwev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > I''m using the excellent flex_image plugin for a new project and have > > > > > > hit a bit of a road block. > > > > > > > I need to import a large number of images and so have been looking > > at > > > > an alternative to just using a simple html form to upload the images > > > > one at a time. > > > > > > > something like.. > > > > > > > fp = open(''one.jpg'',''rb'') > > > > file = fp.read > > > > p = Picture.create(:data=>file) > > > > > > > gives an error.. > > > > > > > FlexImage::Model::InvalidImage: Uploaded file contains no binary > > > > data. Be sure that {:multipart => true} is set on your form. > > > > from > > ./script/../config/../config/../vendor/plugins/flex_image/ > > > > lib/flex_image/model.rb:153:in `data='' > > > > > > > Anyone have an idea how I can get round this? > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There is an easier way. Just wrap your data in a StringIO object: file = open(filename, ''rb'').read Photo.create :data => StringIO.new(file) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---