Check the size of a WWW file

Hi!
I hope this is the right section for this question:

I need to download a video file in the Streaming Assets folder from another PC in LAN.

IEnumerator ImportVideo () {
        using (WWW www = new WWW ("http://192.168.2.244/VideoInterface/video/1.mp4")) {
            yield return www;
            if (www.error != null) {
                Debug.Log (www.error);
            } else {
                string write_path = Application.dataPath + "/StreamingAssets/Video/1.mp4";
                System.IO.File.WriteAllBytes (write_path, www.bytes);
            }
        }

    }

I’ve no problem with this but now I want to check if the file is already in the directory. In that case I don’t want to download it. Is it possible? I thought about checking the name and the size but I can’t find a way to check the size…

if you have access to the file, then

but could take the size after download also, www.bytes.length,
also Unity - Scripting API: WWW.bytesDownloaded

ok, so I need to download the file anyway…
Thank you

if want to get size without downloading, could ask from server (requires some server side script to return file size)
or compare file hash code from server and from local file.

1 Like

Yes, I was thinking the same. I’ll try, thanks!

You can also try using UnityWebRequest, which is more flexible than WWW. You could send HEAD request instead of GET, if server supports it, it would return you only HTTP headers, but not the file. Then check the Content-Length header, it should match the file size.

2 Likes