Hi I have a site which is working quite nicely at the moment but i want
to batch upload a large amount of data from a csv file. Up until now i
have added new items by hand through the forms, now i have a script to
do it. The script is fine up until i try to run the images through
file_column. The problem being that the images are stored as url’s. So
question is how can i present to url’s to file column in a way that it
understands how to follow them and get the files or alternatively how
can i get the images pointed to by the url and then present them to
file_column as if they were uploaded data.
Hi I have a site which is working quite nicely at the moment but i want
to batch upload a large amount of data from a csv file. Up until now i
have added new items by hand through the forms, now i have a script to
do it. The script is fine up until i try to run the images through
file_column. The problem being that the images are stored as url’s. So
question is how can i present to url’s to file column in a way that it
understands how to follow them and get the files or alternatively how
can i get the images pointed to by the url and then present them to
file_column as if they were uploaded data.
I think the best way is to handle such cases manually and not alter the
file_column. Something like that:
Dear Maxim
Thank you very much for replying but sadly I’m not yet good enough to
understand your fancy code.
I used it as follows but recieced the following error:
Sorry i usually have a better crack at solving issues but I don’t
understand what is going on in the section that begins (class <<
uploadedfile; self; end).class_eval. If you get time to reply that would
be excellent, if not thanks for giving me something to investigate
further.
regards
c
NameError: undefined local variable or method uploadedfile' for VoObject:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1129:in method_missing’
Hi I have a site which is working quite nicely at the moment but i want
to batch upload a large amount of data from a csv file. Up until now i
have added new items by hand through the forms, now i have a script to
do it. The script is fine up until i try to run the images through
file_column. The problem being that the images are stored as url’s. So
question is how can i present to url’s to file column in a way that it
understands how to follow them and get the files or alternatively how
can i get the images pointed to by the url and then present them to
file_column as if they were uploaded data.
I think the best way is to handle such cases manually and not alter the
file_column. Something like that:
Thank you very much for replying but sadly I’m not yet good enough to
understand your fancy code.
Sorry i usually have a better crack at solving issues but I don’t
understand what is going on in the section that begins (class <<
uploadedfile; self; end).class_eval. If you get time to reply that would
be excellent, if not thanks for giving me something to investigate
further.
“class << uploadedfile; self; end” is a common technique to get
singleton class for that very instance to be able to extend it. I think
it could be done in a more simple way, I just took a code from
file_column’s test method that simulate an uploaded file.
In Rails, uploaded file is an IO object or the like (which has “read”
method) extended with some instance methods (local_path,
original_filename, content_type).
Regarding your error, I think you haven’t required ‘open-uri’ library
and this line
uploadedfile = StringIO.new(remote.read)
haven’t got executed. That’s probably why you’ve got “undefined
variable” error. I suggest you to put all the code inside open(uri)
block so you’ll ensure that nothing will happen if it is unable to open
that uri.