Forum: Ruby File copy

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3d9e26d3be3e7fcf93aca6574bc77a20?d=identicon&s=25 Tushar Gandhi (gandhi-tush)
on 2009-04-06 08:54
Hi,
I am facing a problem to copy the file.

I am getting path of the file like this
"http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/....
I want to copy this file locally. I am trying to do this by using

File.copy("http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/...

I am getting an error
Invalid argument -
http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/...

I know that this is not a directory path. Is any one knows how to copy
this file?

Thanks
Tushar
Da22709962fc0cf31068e779c78ab6be?d=identicon&s=25 Raveendran .P (jazzezravi)
on 2009-04-06 09:18
> I know that this is not a directory path. Is any one knows how to copy
> this file?

Hi Gandhi,

Try this code which is mentioned in my blog

http://raveendran.wordpress.com/2009/04/06/save-im...


Regards,
P.Raveendran
http://raveendran.wordpress.com
3d9e26d3be3e7fcf93aca6574bc77a20?d=identicon&s=25 Tushar Gandhi (gandhi-tush)
on 2009-04-06 09:58
Hi,

I write the code like this
"
 browser=Watir::IE.new
    browser.visible=false
    browser.goto(params[:photo_url])

    idx = 0

    # using the images collection, iterate through all of the images on
a page
    browser.images.each do |x|
      idx += 1
      # apparently the string accepted by the string method will not
allow variable substitution
      original_type= x.src[-4,4]
      type=".gif" if original_type == ".gif"
      type=".jpg" if original_type == ".jpg"
      type=".png"if original_type == ".png"
      type=".bmp" if original_type == ".bmp"
      type="jpeg" if original_type == ".jpeg"
      x.save('/images/')
    end
"
I am getting an error

" The AutoIt dll must be correctly registered for this feature to work
properly "
How to resolve this?
Thanks,
Tushar

jazzez ravi wrote:
>
>> I know that this is not a directory path. Is any one knows how to copy
>> this file?
>
> Hi Gandhi,
>
> Try this code which is mentioned in my blog
>
> http://raveendran.wordpress.com/2009/04/06/save-im...
>
>
> Regards,
> P.Raveendran
> http://raveendran.wordpress.com
9b3d14efbedc70a652b441b2ec6b871b?d=identicon&s=25 Loga Ganesan (loganathan1)
on 2009-04-06 09:59
Tushar Gandhi wrote:
> Hi,
> I am facing a problem to copy the file.
>
> I am getting path of the file like this
> "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/....
> I want to copy this file locally. I am trying to do this by using
>
> 
File.copy("http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/...
>
> I am getting an error
> Invalid argument -
> http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/...
>
> I know that this is not a directory path. Is any one knows how to copy
> this file?
>
> Thanks
> Tushar


Why can't you use wget command in system or popen to download it ?
It's my suggestion
Da22709962fc0cf31068e779c78ab6be?d=identicon&s=25 Raveendran .P (jazzezravi)
on 2009-04-06 10:08
Tushar Gandhi wrote:

>     browser.goto(params[:photo_url])

Hi Gandhi,


Oops. please try with separate .rb file first.

After that try to implement in rails.

Regards,
P.Raveendran
http://raveendran.wordpress.com
3d9e26d3be3e7fcf93aca6574bc77a20?d=identicon&s=25 Tushar Gandhi (gandhi-tush)
on 2009-04-06 10:10
Hi,
I went through this link
http://www.mail-archive.com/wtr-general@rubyforge....
and my dll registered successfully.
I changed my code like this
"
 browser=Watir::IE.new
    browser.visible=true
    browser.goto(params[:photo_url])

    idx = 0

    # using the images collection, iterate through all of the images on
a page
    browser.images.each do |x|
      idx += 1
      # apparently the string accepted by the string method will not
allow variable substitution
      original_type= x.src[-4,4]
      type=".gif" if original_type == ".gif"
      type=".jpg" if original_type == ".jpg"
      type=".png"if original_type == ".png"
      type=".bmp" if original_type == ".bmp"
      type="jpeg" if original_type == ".jpeg"
      x.save('E:\Rails2.2\integrateSNS\public\images')
    end
"
It open a new tab and open that image and also open windows standard sve
pop up and hangs.
What should I do for this?

Thanks,
Tushar
Da22709962fc0cf31068e779c78ab6be?d=identicon&s=25 Raveendran .P (jazzezravi)
on 2009-04-06 10:19
Hi Gandhi,

Please try to run the code in separate .rb file. Update here in case you
get any errors.
E16e84e861c1815ce11ba7bd851c857d?d=identicon&s=25 lasitha (Guest)
on 2009-04-06 17:47
(Received via mailing list)
On Mon, Apr 6, 2009 at 12:23 PM, Tushar Gandhi <gandhi.tush@gmail.com>
wrote:
> Hi,
>
> 
File.copy("http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/...
>

Hello Tushar,

Take a look at 'net/http', which is included in the ruby standard
library:
http://ruby-doc.org/core-1.9/classes/Net/HTTP.html

For example the following code will download and save the ruby logo
off ruby-lang.org:

require 'net/http'
uri = URI.parse('http://www.ruby-lang.org/images/logo.gif')
Net::HTTP.get_response(uri) do |response|
  File.open('/tmp/logo.gif', 'w') {|f| f.write response.body }
end

There are various other ways to go about doing this - some of which
have been mentioned above - but 'net/http' is a good place to start.

solidarity,
lasitha.
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 Jesús Gabriel y Galán (Guest)
on 2009-04-06 18:33
(Received via mailing list)
On Mon, Apr 6, 2009 at 5:45 PM, lasitha <lasitha.ranatunga@gmail.com>
wrote:
>
> For example the following code will download and save the ruby logo
> off ruby-lang.org:

Another possibility:

irb(main):001:0> require 'open-uri'
=> true
irb(main):003:0> open("http://www.ruby-lang.org/images/logo.gif") do |f|
irb(main):004:1* File.open("logo.gif", "w"){|out| out.write f.read}
irb(main):005:1> end


Regards,

Jesus.
This topic is locked and can not be replied to.