Rev cannot open my jpeg ! - and some serious thinking
Mark Smith
lists at futilism.com
Wed Jul 1 05:42:38 EDT 2009
Sarah, to get the size of what will be returned by a "get url", you
need to issue an HTTP HEAD request, which will return the http
headers that would be returned from a GET request, but without the
actual content. Something like this in a button script:
on mouseUp
put "http://futsoft.futilism.com/revolutionstuff.html" into tUrl
put urlHead(tUrl)
end mouseUp
function urlHead pUrl
set the itemdelimiter to "/"
put "HEAD /" && item 4 to -1 of pUrl && "HTTP/1.1" & cr into tHeads
put "Host:" && item 3 of pUrl & cr after tHeads
put "Accept: */*" after tHeads
libUrlSetCustomHttpHeaders tHeads
get url pUrl
return libUrlLastRhHeaders()
end urlHead
should return something like:
HTTP/1.1 200 OK
Date: Wed, 01 Jul 2009 09:30:23 GMT
Server: Apache
Last-Modified: Sun, 26 Apr 2009 21:55:28 GMT
ETag: "32224e1-19ca-49aab400"
Accept-Ranges: bytes
Content-Length: 6602
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
where the "Content-Length" line is the size in bytes of the content.
Sometimes this seems to take quite a few seconds, and I don't know
why (I think libUrl doesn't like non-GET/POST requests), but if you
have curl available, you can do this:
get shell("curl -s -I " && quote & tUrl & quote) -- that '-I' is an
uppercase 'I' for India
which will give you the same thing, without any delay.
Best,
Mark
On 1 Jul 2009, at 09:07, Sarah Reichelt wrote:
> With regard to Wikipedia supplying enormous images, does anyone know a
> method for determining the size of a download before it starts? Once
> the download has begun the URLStatus gives the total size, but it
> would be really useful to get this before starting. I guess I can see
> whether I can get a directory listing but I doubt that would be
> permitted. The only other option I can think of is to start
> downloading invisibly, and stop after the first status report, suing
> that data to see whether the incoming image file is too large.
More information about the use-livecode
mailing list