File copy

T

Tushar Gandhi

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/90/75/704291251/457931_8289306.jpg".
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/90/75/704291251/457931_8289306.jpg","/images");

I am getting an error
Invalid argument -
http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/90/75/704291251/457931_8289306.jpg

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

Thanks
Tushar
 
T

Tushar Gandhi

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
 
L

Loga Ganesan

Tushar said:
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/90/75/704291251/457931_8289306.jpg".
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/90/75/704291251/457931_8289306.jpg","/images");

I am getting an error
Invalid argument -
http://photos-d.ak.fbcdn.net/photos-ak-snc1/v2574/90/75/704291251/457931_8289306.jpg

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
 
T

Tushar Gandhi

Hi,
I went through this link
http://www.mail-archive.com/[email protected]/msg06628.html
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
 
J

jazzez ravi

Hi Gandhi,

Please try to run the code in separate .rb file. Update here in case you
get any errors.
 
L

lasitha


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.
 
J

Jesús Gabriel y Galán

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,949
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top