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
-
JereMiami
- Posts: 127
- Joined: Mon Nov 03, 2014 12:17 am
Post
by JereMiami » Sat Oct 21, 2023 10:52 pm
What am I doing wrong? Neither "there is a file" or "there is not a file" gives me a result that there actually is a file (true/false, respectively).
Code: Select all
set the defaultFolder to specialFolderPath("documents")
put URL "https://thedomain.com/thefile.jpg" into tUrl
put specialFolderPath("documents") & "/thefile.jpg" into tPath
libURLDownloadToFile tUrl, tPath ------the new file
wait 2 ticks
set the defaultFolder to specialFolderPath("documents")
answer there is a file "thefile"
In this particular example I get false. But the file does exist and in that location. What gives?
Last edited by
JereMiami on Sun Oct 22, 2023 6:31 pm, edited 3 times in total.
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sun Oct 22, 2023 10:50 am
Also, in the first line, you do not want to put URL ...
Code: Select all
// the line below will attempt to put the data returned from the URL into the variable
// put URL "https://thedomain.com/thefile.jpg" into tUrl
// you just want the string literal in the variable:
put "https://thedomain.com/thefile.jpg" into tUrl
-
JereMiami
- Posts: 127
- Joined: Mon Nov 03, 2014 12:17 am
Post
by JereMiami » Sun Oct 22, 2023 6:25 pm
Thanks everyone. I needed a callback to cause the code to wait for the download to be complete before starting the remainder of the code. Here is that code (I got from anther post) if anyone is interested:
Code: Select all
set the defaultFolder to specialFolderPath("documents")
put URL "https://thedomain.com/thefile.jpg" into tUrl
put specialfolderpath("documents") & "/thefile.jpg" into tPath
libURLDownloadToFile tUrl, tPath, "ee.config.downloadComplete" ---- there are three commands for this callback below
wait until _ee.config.getDownloadStatus() is "Download complete" with messages
answer there is a file "thefile"
---...
private function _ee.config.getDownloadStatus
if sDownloadComplete is "Download complete" then
put empty into sDownloadComplete
return "Download complete"
else
return sDownloadComplete
end if
end _ee.config.getDownloadStatus
private command _ee.config.setDownloadStatus pVal
put pVal into sDownloadComplete
end _ee.config.setDownloadStatus
on ee.config.downloadComplete pUrl, pStatus
put "Download complete" into sDownloadComplete
end ee.config.downloadComplete
-
SparkOut
- Posts: 2943
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sun Oct 22, 2023 8:16 pm
Both of the previous answers still apply.
-
JereMiami
- Posts: 127
- Joined: Mon Nov 03, 2014 12:17 am
Post
by JereMiami » Mon Oct 23, 2023 2:18 am
Sparkout
Yes. They do. And, Because I had a jpg already in the documents with the same name, it appeared to have been solved with the callback. But oh no. It actually was still having an error because of the keyword URL before the "https//:yourdomain..." parameter in the libURLDownloadToFile command.
So thank you very much for that. Absolutely, one hundred percent, do not put the keyword URL before the actual url when entering the url paramenter for libURLDownloadToFile command!!!
Emily
As to using "profile" versus "profile.jpg" that is correct either way, but you are correct; the former you would have to set the defaultfolder to use just "profile."
Thanks everyone.
Code: Select all
local sDownloadComplete
on mouseUp
put empty into sDownloadComplete
put "https://thedomain/thefile.jpg" into tUrl
put specialfolderpath("documents") & "/profile.jpg" into tPath
delete file tPath ---the old file
libURLDownloadToFile tUrl, tPath, "downloadComplete" ---the callback is below
wait until sDownloadComplete is not empty with messages
if there is a file tPath then ---the new file
set the filename of img "profileImage" to tPath
else
set the filename of img "profileImage" to specialFolderPath("resources") & "/default.jpg"
end if
end mouseUp
command downloadComplete pUrl,pStatus
put empty into sDownloadComplete
switch
case URLStatus(pUrl) is "downloaded"
put "downloadComplete" into sDownloadComplete
return sDownloadComplete
break
case URLStatus(pUrl) is "error"
put "error" into sDownloadComplete
return sDownloadComplete
break
end switch
end downloadComplete
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Oct 23, 2023 10:03 am
Since I NEVER use something like "wait until...", I would do it this more effective way:
Code: Select all
local tPath,tDefaultPath
on mouseUp
put "https://thedomain/thefile.jpg" into tUrl
put specialfolderpath("documents") & "/profile.jpg" into tPath
put specialFolderPath("resources") & "/default.jpg" into tDefaultPath
libURLDownloadToFile tUrl, tPath, "downloadComplete"
end mouseUp
command downloadComplete pUrl,pStatus
switch pStatus
##! ;-)
case "downloaded"
set the filename of img "profileImage" to tPath
break
case "error"
set the filename of img "profileImage" to tDefaultPath
## optional: answer "Error..."
break
end switch
end downloadComplete