I'm working on updating my developer tools for servers 2.0.
I'm having trouble having my tool upload a server build. First, I call
GetAssetUploadUrlAsync() to get a URL to post my build to. Then, I run a PUT request to upload my build.
Specifically, I'm currently using this code to do the PUT request. I already use this exact code to successfully upload builds for legacy matchmaking with my live title, from the URL fetched via
GetServerBuildUploadUrl(), so I am fairly confident that the PUT code should be okay.
static bool PutFile(string putURL, byte[] payload, Action onSuccess) { var request = (HttpWebRequest)WebRequest.Create(putURL); request.Method = "PUT"; request.ContentType = "application/x-zip-compressed"; if (payload != null) { Stream dataStream = request.GetRequestStream(); dataStream.Write(payload, 0, payload.Length); dataStream.Close(); } else { Dev.LogWarning(string.Format("ERROR: Byte arrry was empty or null")); return false; } Dev.Log("Starting HTTP PUT..."); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Dev.Log("...HTTP PUT Successful"); if (onSuccess != null) onSuccess(); return true; } else { Dev.LogWarning(string.Format("ERROR: [{0}] -- {1}", response.StatusCode, response.StatusDescription)); return false; } }
After running my PutFile code on the URL retrieved from GetAssetUploadUrlAsync, the console loads for a while (which suggests the bytes reach the server), but I get a
The remote server returned an error: (400) Bad Request
in response.
I'm not sure how to debug it further. I've tried waiting 15 minutes and running the request again, but it still fails with the same response.
I'm suspecting maybe I need to adjust the ContentType in my HttpRequest, but I'm not sure what else to put it, since I'm uploading a zip file (the same type of zip file as I'm uploading for my legacy server).