How can I know an image downloaded?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Location: Khanom, Nakhon Si Thammarat, Thailand
Contact:

How can I know an image downloaded?

Post by paulsr » Wed Aug 15, 2012 3:35 am

Folks:

I've seen this question in other forum posts, but I can't find an answer...

If I download an image with something like:

Code: Select all

put url t_img_url into url ("binfile:" & t_location)
... is there any easy way to know that it worked?

If the remote file does not exist, the web server generates a 404 page and sends that instead. So whether the image downloads, or a 404 page downloads, the local file is created, and the command appears to have been successful.

I can't find anything that generates an error.

Do I have to inspect the local file to see if it's an html 404 page?

TIA for any help...

--paul

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How can I know an image downloaded?

Post by dunbarx » Wed Aug 15, 2012 4:56 am

Hi.

I don't use this sort of thing, but in general, as these things go, don't you think that checking the result of the url command is the same as checking the result? By that I mean, literally, the result, as if you clicked "Cancel" in an "Ask" dialog.

No shame in checking the success of your query with standard tools.

Craig Newman

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Location: Khanom, Nakhon Si Thammarat, Thailand
Contact:

Re: How can I know an image downloaded?

Post by paulsr » Wed Aug 15, 2012 5:15 am

Thanks Craig, but "the result" is always blank, because even if a 404 page is downloaded, LiveCode doesn't see it as an error, because something was downloaded even if it wasn't the image I wanted.

--paul

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How can I know an image downloaded?

Post by Klaus » Wed Aug 15, 2012 12:01 pm

Hi Paul,

why not download into a variable first, check this and then save to disk on success?

Code: Select all

...
put url t_img_url into tImageVariable

## Network problem?
if the result <> empty then
  ## error
  exit HANDLERNAME
end if

## check content of variable:
if tImageVariable contains "404" then
  ## or maybe ... contains "</html>"?

  ## error
  exit HANDLERNAME
end if
## Finally:
put tImageVariable into url ("binfile:" & t_location)
...
Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How can I know an image downloaded?

Post by dunbarx » Wed Aug 15, 2012 3:02 pm

I was being obtuse, as usual, in trying to relate the standard checking of the "result" to checking the result of your url query. I just meant to say that you should check your, er, results.

paulsr
Posts: 222
Joined: Thu Jul 19, 2012 9:47 am
Location: Khanom, Nakhon Si Thammarat, Thailand
Contact:

Re: How can I know an image downloaded?

Post by paulsr » Thu Aug 16, 2012 7:53 am

Thanks Klaus. I guess the answer is "yes" ... I do have to check the file to see if it contains "404".

Or, as you say "</html>".

I guess to be sure, I shd also check for "</HTML>" and "404". It's possible a binary image file could contain the sequence "404".

--paul

Klaus
Posts: 13878
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How can I know an image downloaded?

Post by Klaus » Thu Aug 16, 2012 10:49 am

Hi Paul,
paulsr wrote:Or, as you say "</html>".
I guess to be sure, I shd also check for "</HTML>" and "404". It's possible a binary image file could contain the sequence "404".
--paul
sure, just look for something that looks like HTML code and is definitively NOT in the binary data of an image.


Best

Klaus

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: How can I know an image downloaded?

Post by Mag » Sat Apr 06, 2013 3:40 pm

Hi all! Interesting discussion, and if I would like to just know if a particular file exist, before to use the "load URL" or "put URL" commands?

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: How can I know an image downloaded?

Post by Thierry » Sat Apr 06, 2013 3:48 pm

Mag wrote:Hi all! if I would like to just know if a particular file exist?
You can check in the Dictionnary:

there is and/or exists

Oups sorry; this applies only on local files
I was too fast reading your post :roll:

Thierry
Last edited by Thierry on Sat Apr 06, 2013 9:29 pm, edited 1 time in total.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: How can I know an image downloaded?

Post by Simon » Sat Apr 06, 2013 9:09 pm

To find if files exists in an online folder you need to run a php script:

Code: Select all

<?php
$path = ".";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh)) !== false) {
    if($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") {
        echo "<a href='$path/$file'>$file</a><br /><br />";
        $i++;
    }
}
closedir($dh);
?> 
Just use the "put url.../myList.php" to get a listing of all the files in the directory.
This is a simple php script and only returns the filenames, google "index of files in directory php" to get many more with tons of features.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: How can I know an image downloaded?

Post by Mag » Mon Apr 08, 2013 11:25 am

Thank you Simon! This will be very useful to avoid to get wrong remote files due to "404" forwards.

PS
Thierry, no problem, actually my post was not very clear, in every way thank you for your replay!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”