Page 1 of 1

Download not working with link or libURLDownloadToFile

Posted: Mon Mar 10, 2014 8:38 pm
by Ken3D
I can't get files to download from my browser app. I'm using revBrowser and its working great to host web pages in my LC project - but when I click on a download link on the page nothing happens. The files download fine when using Safari or Firefox, but inside LC no.

I added a function that uses the libURLDownloadToFile command to see if that would force the file to download but I'm still not seeing anything happen. The code I'm using for this is:

Code: Select all

on browserDownloadRequest sBrowserId, pUrl
   answer pUrl
   libURLDownloadToFile pUrl, specialFolderPath("desktop")
   answer question "To download files you'll need to swich to an external browser application. Would you like to do that now?" with "Not Now" or "Yes" titled "Go to browser to download?"
   if it is "Yes" then
      launch url urlCache
   end if
   abIamNotBusy
end browserDownloadRequest
The "browserDownloadRequest" catches the request and runs the above code. I'm using the "answer pUrl" in there just so I can see what the requested download URL is to make sure it's correct. You can see I also added the answer question asking the user if they want to use an external browser just because I haven't been able to get direct downloading to work.

I would post the URL for the page with the download link but the forum is telling me I don't have permission to post URLs - but its a standard web address with the last entry in the line a .zip file name.

Is there some initialization I need to do in order to get downloads to work in revBrowser? What am I missing? I've tried this on two MacBook Pros - one running Mavericks and the other 10.7.5.

Thanks.

Re: Download not working with link or libURLDownloadToFile

Posted: Mon Mar 10, 2014 9:27 pm
by BvG
As far as I can read in the dictionary, browserDownloadRequest is more of a notification that the browser will now download a file, and you don't need to do anything... at least on Mac OS X.

In addition you're trying to download the url twice in the code too! (launch vs liburldownladotofile) But that might be from trying so many things?

Re: Download not working with link or libURLDownloadToFile

Posted: Mon Mar 10, 2014 9:46 pm
by Ken3D
Thanks for the quick responses - first to you BvG: [well - there was another response here but now it's gone - so just responding to BvG]
Yeah, I only added the function that utilizes the browserDownloadRequest message because downloads weren't working. That function first started as just the notification to the user giving them the option to go to their default browser to download the file - like this:

Code: Select all

on browserDownloadRequest sBrowserId, pUrl
   answer question "To download files you'll need to swich to an external browser application. Would you like to do that now?" with "Not Now" or "Yes" titled "Go to browser to download?"
   if it is "Yes" then
      launch url urlCache
   end if
   abIamNotBusy
end browserDownloadRequest
You're right that I'm trying to download twice - but I believe the first request is the link in the web page (the revBrowser should allow that to happen) but when I saw that the first one wasn't working I tried the libURLDownloadToFile command to see if that would work - but no go. I suppose you could argue there's a third download request - but that one is optional for the user and takes them to their default browser - and in that case it only takes them to the page with the download link (that's what the urlCache is for - it's holding the URL for the page the download link is on).

Did I misunderstand your response BvG?

Re: Download not working with link or libURLDownloadToFile

Posted: Mon Mar 10, 2014 9:58 pm
by BvG
I tried to say that you should read the dictionary entry, and not try to do random things 8)

You say that the download, as initiated within the browser instance is not starting, despite the same link/url working from a normal safari window. the dictionary says it should start. If all that is right, then I suggest you file a bug report:

http://quality.runrev.com

Don't forget to include a simple to follow step by step guide.

Re: Download not working with link or libURLDownloadToFile

Posted: Tue Mar 11, 2014 12:03 am
by Ken3D
Bug submitted. Is there anyone out there who is finding success doing downloads of a .zip file from the revBrowser on a Mac?

Re: Download not working with link or libURLDownloadToFile

Posted: Tue Mar 11, 2014 12:41 am
by Simon
I wonder if it has to do with no filename?
libURLDownloadToFile pUrl, specialFolderPath("desktop")
Does not specify it.
You'd get the filename from
set itemDel to "/"
put the last item of pUrl into tName
libURLDownloadToFile pUrl, specialFolderPath("desktop") & "/" & tName.

Simon

Re: Download not working with link or libURLDownloadToFile

Posted: Tue Mar 11, 2014 8:06 am
by jacque
Also, the variable 'urlcache' has no value that I can sse.

Re: Download not working with link or libURLDownloadToFile

Posted: Tue Mar 11, 2014 9:11 am
by Ken3D
jacque wrote:Also, the variable 'urlcache' has no value that I can sse.
That variable is a global and is filled with the URL earlier in another function in my script. I apologize that the code I pasted here is not fully self contained - I realize that makes it difficult to follow what I'm saying.

Re: Download not working with link or libURLDownloadToFile

Posted: Tue Mar 11, 2014 9:14 am
by Ken3D
Simon - thanks for the ideas and code snippet. I'll have to take some time to look up some of what you're suggesting using the LC dictionary to see if can follow what your saying. I think I am providing a proper path and URL in my code - but maybe not.

Re: Download not working with link or libURLDownloadToFile

Posted: Thu Jun 05, 2014 1:34 pm
by istech
I have had a few issues using LibURLDownloadToFile to get a download. As I was playing around I decided to try to "lock screen" before calling the "LibURLDownloadToFile" and it worked a lot better. This maybe my case with my code but worth a try good luck.