Can you download a file from a URL without the full file name?

So as you can see from my partial code below I am trying to download a file from VRChat’s website. Everything works if I use a full file name however I am running into an issue. The team who uploads their files online change the file name every time they update it. For instance, the file name currently looks like this: “VRCSDK2-2021.04.21.11.58_Public.unitypackage”. If they update their file then the date and time changes and my code breaks. Is there a way to write my file name so that it will always download the latest version and not break when they update? Such as a way to have the code look for any file starting with “VRCSDK2”?
Thanks for all the help!

        private static string sdkStart = "https://files.vrchat.cloud/sdk/";

...

        private static void DownloadSDK(string assetName)
        {
            GetPath();
            WebClient w = new WebClient();
            w.Headers.Set(HttpRequestHeader.UserAgent, "Webkit Gecko wHTTPS (Keep Alive 55)");
            w.QueryString.Add("assetName", assetName);
            w.DownloadFileCompleted += FileDownloadCompleted;
            w.DownloadProgressChanged += FileDownloadProgress;
            string url = sdkStart + assetName;
            w.DownloadFileAsync(new Uri(url), Path + assetName);
        }

They would have to provide a URL with that functionality. There’s nothing you can do as a client to get this behavior. Often they will provide a -latest url or something.

So another question then… if there is a link that redirects to the download of the SDK such as:
https://vrchat.com/download/sdk2
can you download the file from a redirect? I could not find a way to do that prior.

This is working for me properly:

private static void DoDownload()
{
    var w = new WebClient();
    w.Headers.Set(HttpRequestHeader.UserAgent, "Webkit Gecko wHTTPS (Keep Alive 55)");
    w.DownloadFileCompleted += FileDownloadCompleted;
    w.DownloadProgressChanged += FileDownloadProgress;
    var url = "https://vrchat.com/download/sdk2";
    w.DownloadFileAsync(new Uri(url), Application.dataPath + "/assetName.unitypackage");
}
private static void FileDownloadProgress(object sender, DownloadProgressChangedEventArgs e) => Debug.Log($"Progress: {e.ProgressPercentage}%");
private static void FileDownloadCompleted(object sender, AsyncCompletedEventArgs e) => Debug.Log("Done.");

7120285--850090--screenshot1.png

3 Likes

Thank you so much ;-; I had much such a minor oversight and your code has completely fixed my issue!