get the file size of a zip on a server

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
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

get the file size of a zip on a server

Post by jmburnod » Mon Nov 19, 2012 7:09 pm

Hi All,
Is there a way to get the size file of a zip on a server ?
Best regards
Jean-Marc
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: get the file size of a zip on a server

Post by jacque » Tue Nov 20, 2012 9:02 pm

There may be an ftp command, I'm not sure. Or you can write a little script for the server in PHP, or in LiveCode if you have LiveCode server installed, and ask the script to send the file size back.

Is this for your progress bar? If so, you can use the parameters that are sent to the urlProgress handler if your sever sends those.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: get the file size of a zip on a server

Post by jmburnod » Tue Nov 20, 2012 10:17 pm

Hi Jaque,
Thank again for yours suggests.
Is this for your progress bar? If so, you can use the parameters that are sent to the urlProgress handler if your sever sends those.
Yes, but urlprogress is IOS only and the server has to send the total data size
bytesTotal - Is empty if the web server does not send the total data size.
I search also a way to have a progressbar during a download on OSX and i thought there is a simple way to get the file size that should be useful for IOS and OSX

I keep the other ways in my head (i have to study ftp command and "little script for server in PHP") :)

Best regards
Jean-Marc
https://alternatic.ch

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: get the file size of a zip on a server

Post by jacque » Wed Nov 21, 2012 5:20 am

URLProgress works on Android too. For all desktop platforms, you can use libURLSetStatusCallback. That gives similar information, including the total byte count if your server sends that. For both urlProgress and libURLSetStatusCallback, it is helpful to set up a switch statement and catch all the status messages. When the status is "loading" you can examine the different items in the status string to see what the download byte total is. I usually see a total count on the servers I have tried so far.

Here is part of an example. In the main handler where you start the download, set the status callback:

Code: Select all

 libUrlSetStatusCallback "checkStatus", (the long id of me)
Then LiveCode will send that message frequently during the file transfer. Write a "checkStatus" handler to catch that message and examine the parameters:

Code: Select all

 on checkStatus pURL,pStatus
  put pStatus & cr before fld "statusFld" -- keep a log here
  switch (item 1 of pStatus)
    case "uploading"
    case "loading"
      set the endvalue of sb "progressbar" to item 3 of pStatus
      set the thumbpos of sb "progressbar" to word 1 of item 2 of pStatus -- strip space
      break
    case "uploaded"
    case "downloaded"
      set the thumbpos of sb "progressbar" to the endvalue of sb "progressbar"
      -- do other processing here
      break
    case "error"
    case "timeout"
      -- do something with the error here; notify user, etc.
      break
    default -- contacted, requested, etc.
      set the thumbpos of sb "progressbar" to 0
  end switch
end checkStatus
The log field should show you the status of the upload or download and if you have a progress bar it will update.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: get the file size of a zip on a server

Post by jmburnod » Wed Nov 21, 2012 11:59 am

Yes, libUrlSetStatusCallback is a better way than using the libURLDownloadToFile callback
It work fine
Thank again
Jean-Marc
https://alternatic.ch

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: get the file size of a zip on a server

Post by jmburnod » Mon Nov 26, 2012 3:29 pm

Hi All

I met a mistake with the downloaded message of libUrlSetStatusCallback
It seem libUrlSetStatusCallback work fine to get bytesReceived,bytesTotal but not to catch the download end which is sent before the real download is finished.
Just after the downloaded message a revZipOpenArchive (to list the zip content) return an error "ziperr,Not a zip archive"

There is a stack in attachment with the two methods. It download a zip with 50images (1.4 Mo) on the documents folder.

Meth1. Doesn't work
• using libUrlSetStatusCallback to get bytesReceived,bytesTotal for progressbar and downloaded message

Meth2. Works
• using libUrlSetStatusCallback to get bytesReceived,bytesTotal for progressbar
• using libURLDownloadToFile callback to catch the download end.

Best regards
Jean-Marc
Attachments
DownloadZipOSX502.livecode.zip
(10.29 KiB) Downloaded 328 times
https://alternatic.ch

kbirand
Posts: 15
Joined: Tue Oct 30, 2012 1:28 am

Re: get the file size of a zip on a server

Post by kbirand » Tue Nov 27, 2012 7:00 pm

Dear Jean-Marc,

Did you find a way to get remote file size ?

Koray

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: get the file size of a zip on a server

Post by jacque » Tue Nov 27, 2012 7:29 pm

I haven't had time to look at the example stack, but the OS may need time to finalize the file download. You could try moving the unzipping to a separate handler and then calling that handler in a short amount of time.

Code: Select all

case "downloaded"
      set the thumbpos of sb "progressbar" to the endvalue of sb "progressbar"
      send "unzipFile <filepath> to me in 1 second
      break
Then add a handler "unzipFile pFilePath" and have that handler do the work.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: get the file size of a zip on a server

Post by jmburnod » Tue Nov 27, 2012 11:42 pm

Hi Jacques,
Thank for your suggest. That is the trick.
Signify we don't need libURLDownloadToFile callback, LibUrlSetStatusCallback does the job
Best regards
https://alternatic.ch

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: get the file size of a zip on a server

Post by jmburnod » Tue Nov 27, 2012 11:49 pm

Hi Koray,
Did you find a way to get remote file size ?
Yes. The last item of parameter 2 of LibUrlSetStatusCallback is the file size (when the file is loading)
Have a look at "LibUrlSetStatusCallback" in the dictionary
""loading,bytesReceived,bytesTotal": the URL data is being received"

Jacques,
Thank for your suggest. That is the trick.
Signify we don't need libURLDownloadToFile callback, LibUrlSetStatusCallback does the job
Best regards
https://alternatic.ch

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: get the file size of a zip on a server

Post by jmburnod » Thu Nov 29, 2012 11:39 am

Hi All
I made a new topic "Download Zip and extract files with progressbar" for next step
http://forums.runrev.com/phpBB2/viewtop ... =8&t=13466
https://alternatic.ch

Post Reply