Download image from URL and save locally |
Author: |
Message: |
ketchup_blade
New Member
Posts: 8
Joined: Jul 2005
|
O.P. Download image from URL and save locally
Hello,
for my script, I need to be able to save locally an image that is available at a specific URL, for example: http://shoutbox.menthix.net/images/smilies/xso_wink.gif
I'm not used to scripting with Jscript, and i can't find a way to download and save this binary file locally.
Any tips?
kb
|
|
12-05-2006 01:39 PM |
|
|
andrewdodd13
Senior Member
Oh so retro
Posts: 870 Reputation: 16
34 / /
Joined: Jan 2005
|
RE: Download image from URL and save locally
You can use the following:
var dlURL = "http://shoutbox.menthix.net/images/smilies/xso_wink.gif";
var localfile = FSO.BuildPath("<PATH TO SAVED LOCATION>");
var ret = Interop.Call('urlmon', 'URLDownloadToFileW', 0, dlURL, localfile, 0, 0);
|
|
12-05-2006 04:14 PM |
|
|
John Anderton
Elite Member
Posts: 3908 Reputation: 80
37 / /
Joined: Nov 2004
Status: Away
|
RE: Download image from URL and save locally
I don't know if i should save this but imo there isn't any practical use to this script. If you know the url why not open it in your browser and save it?
Or if you want to save wallpapers, use a program like Download Accelerator Plus (DAP) that allows addition of links to download queue.
That's just my 2 cents
[
KarunAB.com]
[img]http://gamercards.exophase.com/459422.png[
/img]
|
|
12-05-2006 04:17 PM |
|
|
Felu
Veteran Member
Posts: 2223 Reputation: 72
30 / /
Joined: Apr 2006
Status: Away
|
RE: Download image from URL and save locally
quote: Originally posted by andrewdodd13
var dlURL = "http://shoutbox.menthix.net/images/smilies/xso_wink.gif";
var localfile = FSO.BuildPath("<PATH TO SAVED LOCATION>");
var ret = Interop.Call('urlmon', 'URLDownloadToFileW', 0, dlURL, localfile, 0, 0);
You forgot to declare FSO
code: var FSO = new ActiveXObject('Scripting.FileSystemObject');
quote: Originally posted by John Anderton
I don't know if i should save this but imo there isn't any practical use to this script. If you know the url why not open it in your browser and save it?
With a script . This might be used for downloading Script Updates etc. Though downloading a image is not needed .
This post was edited on 12-05-2006 at 04:34 PM by Felu.
|
|
12-05-2006 04:32 PM |
|
|
andrewdodd13
Senior Member
Oh so retro
Posts: 870 Reputation: 16
34 / /
Joined: Jan 2005
|
RE: RE: Download image from URL and save locally
quote: Originally posted by -!Felu!-
quote: Originally posted by andrewdodd13
var dlURL = "http://shoutbox.menthix.net/images/smilies/xso_wink.gif";
var localfile = FSO.BuildPath("<PATH TO SAVED LOCATION>");
var ret = Interop.Call('urlmon', 'URLDownloadToFileW', 0, dlURL, localfile, 0, 0);
You forgot to declare FSO
code: var FSO = new ActiveXObject('Scripting.FileSystemObject');
Oops, that was silly! I just copied some code I'd already used and modified it slightly, should've checked it
|
|
12-05-2006 04:51 PM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
Joined: Aug 2006
|
RE: Download image from URL and save locally
quote: Originally posted by John Anderton
If you know the url why not open it in your browser and save it?
This could be useful if someone send you a link to an image... (just check start and end of the link for certain text such as .png and so on). You can then download it without having to open a browser or DAP (which both open wuite slow in comparison to just saving it directly and then possibly opening it in a default app such as "Windows Fax and Picture Viewer"
<Eljay> "Problems encountered: shit blew up"
|
|
12-05-2006 05:07 PM |
|
|
John Anderton
Elite Member
Posts: 3908 Reputation: 80
37 / /
Joined: Nov 2004
Status: Away
|
RE: Download image from URL and save locally
quote: Originally posted by -!Felu!-
Though downloading a image is not needed
quote: Originally posted by ketchup_blade's thread title
Download image from URL and save locally
Any other questions?
quote: Originally posted by SpunkyLoveMuff
You can then download it without having to open a browser
Ok. There is clicking a link and seeing it in the browser and deciding if you want to save it and letting a script download the image to a location and open in with windows fax and picture viewer, deciding to keep it or not and then either deleting it or moving it to the appropriate storage place (for people like me to keep different types of wallpapers/images in different folders)
Some how, the earlier seems lesser work to me. And opening a browser, looking and saving would be quicker than the other method
[
KarunAB.com]
[img]http://gamercards.exophase.com/459422.png[
/img]
|
|
12-05-2006 07:21 PM |
|
|
ketchup_blade
New Member
Posts: 8
Joined: Jul 2005
|
O.P. RE: RE: Download image from URL and save locally
quote: Originally posted by John Anderton
I don't know if i should save this but imo there isn't any practical use to this script. If you know the url why not open it in your browser and save it?
Yes there is. Actually, you can't assign the Messenger.MyDisplayPicture property with an image URL (unlike when you select your image manually within Messenger). So if I want to dynamically use an image from the Web, I need to first save it on the disk.
Thanks all for the code, it works! I thought that the FSO didn't work with binary files...
kb
|
|
12-05-2006 08:38 PM |
|
|
|