Hi All...

I've tried both Ken and Gerry's suggestions for downloading images in the 
background via a URL.

In Ken's example, I was able to get the an images downloaded to a img object, 
however when navigating to another card LiveCode started behaving strangely and 
it would lock up for a minute, or two, and then proceed to give me an 
assortment of URL Errors about exceeding the 4000 limit etc., etc. ending with 
a ForceQuit. 

In Gerry's example I managed to download a single image to a folder, but could 
not loop through my list of image URLs in order to download each one.

I attempted to combine both Ken and Gerry's examples, in order to prevent the 
error messages I was receiving in Ken's first example. However, it is not 
working...yet.

Here is what I have:

on mouseUp
   send "downloadImage 1" to me in 0 milliseconds
end mouseUp



on downloadImage idx
if idx <= the number of lines in cd fld "imageURLs" then
set the itemDel to tab
   put item 1 of line idx of cd fld "imageURLs" into tURL
   set the itemDel to "/"
   put the last item of tURL into tImagename
   libUrlDownloadToFile tURL, specialfolderpath ("Documents") & "/WhaleImages/" 
& tImagename
   send "downloadImage "&(idx+1) to me in 0 milliseconds
   end if

end downloadImage

Any suggestions welcome...

Thank you!

John Patten
SUSD


On Feb 21, 2012, at 4:20 AM, Ken Corey wrote:

> Sure, why not?  Let's assume that this is all kicked off from a button press:
> 
> -- I assume you have your URLs in a list
> 
> on mouseUp
>  -- send in 0 milliseconds means call downloadImage as soon
>  --   as this handler is done
>  -- I'd create placeholder graphics where the images might
>  --   go once downloaded, and then you can put them into a list
>  send "downloadImage 1" to me in 0 milliseconds
> end openCard
> 
> on downloadImage idx
>  -- check to see if we've fallen off the end of the list.
>  if idx <= the number of lines of listOfURLs then
>    get URL "http://blah.com/image.gif";
>    -- do something terribly clever to display them to the user.
>    -- e.g. replace the placeholder images above for item idx
>    --
>    -- queue up the next image for download
>    send "downloadImage "&(idx+1) to me in 0 milliseconds
>  end if
> end downloadImage
> 
> So, your app interface should be happily trundling along responding to user 
> input, while the images are being downloaded.  Increase the '0 milliseconds' 
> for more responsiveness.
> 
> This assumes you want the images to come down one at a time.  You /could/ 
> queue up more than one at a time by sending 'downloadImage' to yourself 
> multiple times, but then you'd have to get fancier managing the index.
> 
> You probably don't want to issue all the sends at the same time, because 
> unless you have a monster fat pipe none of them will come down at any 
> rational rate of speed.
> 
> You might also want to think about caching the image somehow.  Check for its 
> existance before the get, and avoid hitting the net at all. (Of course, that 
> means you have to let the user clear the cache, limit the size to which it 
> grows, etc.)
> 
> -Ken
> 
> 
> 
> On 19/02/2012 05:40, johnpat...@me.com wrote:
>> I'm looking to use the Flickr API search routine to return the latest
>> images for a specific tag. I will probably limit it to the 10 or 20 most
>> recent images. I can create the resulting URL to the images from the
>> resulting XML, and set the file name of an image to that URL, looping
>> through the list of images, but I'm curious as to what would be best
>> practice would be to download these images in the background? Ideally I
>> would like the user to be able to use the simulated swipe routines
>> between the images.
>> 
>> The only thing I can think of is downloading the images in the
>> background as soon as the iOS app is launched. Could a script like this
>> be launched at openStack and run in the background?
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to